2009-12-23 19:42:18 -05:00
|
|
|
# Assignment:
|
|
|
|
number: 42
|
|
|
|
opposite_day: true
|
|
|
|
|
|
|
|
# Conditions:
|
|
|
|
number: -42 if opposite_day
|
|
|
|
|
|
|
|
# Functions:
|
2010-01-26 10:52:05 -05:00
|
|
|
square: (x) -> x * x
|
2009-12-23 19:42:18 -05:00
|
|
|
|
|
|
|
# Arrays:
|
|
|
|
list: [1, 2, 3, 4, 5]
|
|
|
|
|
|
|
|
# Objects:
|
|
|
|
math: {
|
|
|
|
root: Math.sqrt
|
|
|
|
square: square
|
2010-01-26 10:52:05 -05:00
|
|
|
cube: (x) -> x * square x
|
2009-12-23 19:42:18 -05:00
|
|
|
}
|
|
|
|
|
2010-01-05 00:34:18 -05:00
|
|
|
# Splats:
|
2010-01-26 10:52:05 -05:00
|
|
|
race: (winner, runners...) ->
|
2010-01-25 00:14:00 -05:00
|
|
|
print winner, runners
|
2010-01-05 00:34:18 -05:00
|
|
|
|
|
|
|
# Existence:
|
2010-01-25 00:14:00 -05:00
|
|
|
alert "I knew it!" if elvis?
|
2010-01-05 00:34:18 -05:00
|
|
|
|
2009-12-23 19:42:18 -05:00
|
|
|
# Array comprehensions:
|
2010-01-26 23:23:59 -05:00
|
|
|
cubed_list: math.cube num for num in list
|