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은....ㅠ
반응형
'BEB > algorithm' 카테고리의 다른 글
| [javaScript/자바스크립트]부분집합인지 확인 (0) | 2022.10.27 |
|---|---|
| [JavaScript/자바스크립트] 순열의 순서 (0) | 2022.10.25 |
| 꼬리재귀, 조합, 하노이 (0) | 2022.10.11 |
| 재귀(recursion) 개념 & JSON (0) | 2022.10.11 |
| 고차함수 filter, map, reduce (0) | 2022.10.03 |
댓글