Last active
August 29, 2015 14:11
-
-
Save lucamolteni/67004d88bf6a1ed88e2e to your computer and use it in GitHub Desktop.
Ancient vs Modern Programming
This file contains hidden or 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
http://www.codewars.com/kata/51c8991dee245d7ddf00000e/solutions/javascript | |
"Complete the solution so that it reverses all of the words within the string passed in." | |
function reverseWords(str){ | |
//split it into words, store in array | |
var words = str.split(" ") | |
var output = ""; | |
//reverse the array and concat each word with space | |
for(var i = words.length-1; i >= 0; i--){ | |
output = output+words[i]; | |
if(i != 0){ | |
output = output+" "; | |
} | |
} | |
return output; // reverse those words | |
} | |
module ReverseWords where | |
reverseWords :: String -> String | |
reverseWords = unwords . reverse . words |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment