Created
October 10, 2014 01:07
-
-
Save cheng470/75b44051c8b1cd663e7c to your computer and use it in GitHub Desktop.
判断是否是奇数,学习函数定义
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
odd = (num) -> | |
unless typeof num is 'number' | |
throw "#{num} is not a number" | |
unless num is Math.round num | |
throw "#{num} is not an integer" | |
unless num > 0 | |
throw "#{num} is not positive" | |
num % 2 is 1 | |
test = (v) -> | |
try | |
console.log odd(v) | |
catch e | |
console.log e | |
test "3" | |
test 3.7 | |
test -3 | |
test 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
3