알고리즘 90 - Stop gninnipS My sdroW!

jabae·2021년 11월 1일
0

알고리즘

목록 보기
90/97

Q.

Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (like the name of this kata).

Strings passed in will consist of only letters and spaces.
Spaces will be included only when more than one word is present.
Examples:

spinWords("Hey fellow warriors") => "Hey wollef sroirraw"
spinWords("This is a test") => "This is a test"
spinWords("This is another test") => "This is rehtona test"

A)

function spinWords(string){
  return string.split(' ').map(el => {
    if (el.length >= 5)
      return el.split('').reverse().join('')
    else
      return el}).join(' ');
}
profile
it's me!:)

0개의 댓글