Skip to content

Instantly share code, notes, and snippets.

@lucamolteni
Last active August 29, 2015 14:11
Show Gist options
  • Save lucamolteni/67004d88bf6a1ed88e2e to your computer and use it in GitHub Desktop.
Save lucamolteni/67004d88bf6a1ed88e2e to your computer and use it in GitHub Desktop.
Ancient vs Modern Programming
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