Created
February 17, 2012 18:59
-
-
Save shaneriley/1854893 to your computer and use it in GitHub Desktop.
WTF CoffeeScript
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
# WHY RETURN STATEMENTS IN CONDITIONAL BLOCKS????? | |
# According to http://coffeescript.org/#conditionals the resulting code does NOT have a return statement. | |
$("dl.card :text").change ()-> | |
$e = $(@) | |
val = $e.val() | |
odd = [] | |
even = [] | |
sum = 0 | |
$.each(val.split(""), (i, v)-> | |
# e should be defined as a local var. Instead, we get: | |
# e; | |
# var e; | |
e | |
if !(i % 2) | |
# If even index, push odd digit as is. Actual: | |
# return odd.push(v); | |
odd.push(v) | |
else | |
e = ("" + (v * 2)).split("") | |
# Odd index; push even digit post-processing. Actual: | |
# return even.push(+e[0] + +e[1]); | |
even.push(+e[0] + +e[1]) | |
) | |
console.dir(odd) | |
console.dir(even) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment