Created
September 19, 2020 06:50
-
-
Save hassan-maavan/ea668caca4b3665c90235e628ca48db7 to your computer and use it in GitHub Desktop.
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 (Just 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" ) => r…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function spinWords(word){ | |
return (word.split(' ').map(reverseWord)).join(' '); | |
} | |
function reverseWord(word) { | |
if((word.split('')).length > 4) { | |
return (word.split('').reverse()).join(''); | |
} else { | |
return word; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment