Created
September 12, 2011 00:49
-
-
Save jeremyckahn/1210378 to your computer and use it in GitHub Desktop.
Equivalent JS and CoffeeScript functions?
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
JS: | |
////////// | |
function getSpeedySignature (ofString) { | |
var sum | |
,len | |
,i; | |
sum = 0; | |
len = ofString.length; | |
for (i = 0; i < len; i++) { | |
sum += ofString.charCodeAt(i); | |
} | |
return sum; | |
} | |
CoffeeScript: | |
////////// | |
getSpeedySignature: (ofString) -> | |
sum = 0 | |
len = ofString.length | |
return ofString.split('').reduce (prev, curr, i) -> | |
+prev + curr.charCodeAt(0) | |
,0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ohhh, that is much nicer. Nice, thanks for the critique! This is the first thing I've written in CoffeeScript, the syntax is quite nice (although it's a big departure from the C-style syntaxes I'm used to).