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

[Codewars] Reversed Words (8 kyu) / JavaScript

by fluss 2023. 1. 21.

https://www.codewars.com/kata/51c8991dee245d7ddf00000e

 

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 all of the words within the string passed in.

Words are separated by exactly one space and there are no leading or trailing spaces.

Example(Input --> Output):

"The greatest victory is that which requires no battle" --> "battle no requires which that is victory greatest The"
 

코드

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

댓글