Last active
October 28, 2015 22:55
-
-
Save chukitow/2f6873e59f6ccff916ee to your computer and use it in GitHub Desktop.
reversing words
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
/* | |
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