Skip to content

Instantly share code, notes, and snippets.

@chukitow
Last active October 28, 2015 22:55
Show Gist options
  • Save chukitow/2f6873e59f6ccff916ee to your computer and use it in GitHub Desktop.
Save chukitow/2f6873e59f6ccff916ee to your computer and use it in GitHub Desktop.
reversing words
/*
Instructions:
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. Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.
Test Cases:
Test.assert_equals(spinWords("Hey fellow warriors"), "Hey wollef sroirraw")
Test.assert_equals(spinWords("This is a test"), "This is a test")
Test.assert_equals(spinWords("This is another test"), "This is rehtona test")
*/
function spinWords(words){
wordsSplited = words.split(' ');
for(var i=0; i<wordsSplited.length; i++){
if(wordsSplited[i].length >= 5){
wordsSplited[i] = wordsSplited[i].split('').reverse().join('');
}
}
return wordsSplited.join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment