Skip to content

Instantly share code, notes, and snippets.

@shaneriley
Created February 17, 2012 18:59
Show Gist options
  • Save shaneriley/1854893 to your computer and use it in GitHub Desktop.
Save shaneriley/1854893 to your computer and use it in GitHub Desktop.
WTF CoffeeScript
# 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