Skip to content

Instantly share code, notes, and snippets.

@hassan-maavan
Created September 19, 2020 06:50
Show Gist options
  • Save hassan-maavan/ea668caca4b3665c90235e628ca48db7 to your computer and use it in GitHub Desktop.
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…
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