Created
February 1, 2016 17:16
-
-
Save giannispan/d887ce9a161f59d2f084 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.
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(str){ | |
var splitWords = str.split(' '); | |
var length = splitWords.length; | |
for(var i = 0; i < length; i++) | |
{ | |
if (splitWords[i].length >= 5 ) | |
{ | |
splitWords[i] = reverseWords(splitWords[i]); | |
} | |
} | |
return splitWords.join(' '); | |
} | |
function reverseWords(str) { | |
var i=str.length; | |
i=i-1; | |
var reversedwords=""; | |
for (var x = i; x >=0; x--) | |
{ | |
reversedwords +=(str.charAt(x)); | |
} | |
return reversedwords; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i did it so