Skip to content

Instantly share code, notes, and snippets.

@naganowl
Created May 23, 2014 21:32
Show Gist options
  • Save naganowl/da938b7c0d8291233cbf to your computer and use it in GitHub Desktop.
Save naganowl/da938b7c0d8291233cbf to your computer and use it in GitHub Desktop.
Simple way to ensure an argument is a valid integer
# Convert `num` into a Number type.
parseNumber: (num) ->
parseNum = parseInt num, 10
# Throw out strings and floats.
if parseNum is +num then parseNum else 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment