본문 바로가기
알고리즘/Codewars

[Codewars] Reversed Strings (8 kyu) / JavaScript

by fluss 2022. 11. 28.

https://www.codewars.com/kata/5168bb5dfe9a00b126000018

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

Complete the solution so that it reverses the string passed into it.

'world'  =>  'dlrow'
'word'   =>  'drow'

 

설명:

전달된 문자열이 뒤집히도록 솔루션을 완성하세요.

'world'  =>  'dlrow'
'word'   =>  'drow'

 

풀이

문자열을 배열로 만든다음 reverse로 뒤집고 다시 합쳐주었다.

 

코드

function solution(str){
  return str.split('').reverse().join('');
}

 

참고

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse

 

댓글