본문 바로가기
BEB/algorithm

[javascript] split의 사용법

by ddanss 2022. 10. 13.
728x90

문자열을 거꾸로 뒤집는 함수다

 

function stringReverse(str) {
  // TODO: 여기에 코드를 작성합니다.
  let res = str.split('').reverse().join('')
  return res;
}

let output = stringReverse('I love sunday monday');
console.log(output); // "yadnom yadnus evol I"

//str.split('')
//['I', ' ', 'l', 'o', 'v', 'e', ' ', 's', 'u', 'n', 'd', 'a', 'y', ' ', 'm', 'o', 'n', 'd', 'a', 'y']

// str.split('').reverse()
// ['y', 'a', 'd', 'n', 'o', 'm', ' ', 'y', 'a', 'd', 'n', 'u', 's', ' ', 'e', 'v', 'o', 'l', ' ', 'I']

//str.split('').reverse().join('')
//yadnom yadnus evol I

 

c++에 비해서 생각보다 이것저것 기능이 많은것같다..

STL은....ㅠ

반응형

댓글