2009-12-23 19:42:18 -05:00
|
|
|
# Assignment:
|
2010-07-29 00:51:35 -04:00
|
|
|
number = 42
|
|
|
|
opposite = true
|
2009-12-23 19:42:18 -05:00
|
|
|
|
|
|
|
# Conditions:
|
2010-07-29 00:51:35 -04:00
|
|
|
number = -42 if opposite
|
2009-12-23 19:42:18 -05:00
|
|
|
|
|
|
|
# Functions:
|
2010-07-29 00:51:35 -04:00
|
|
|
square = (x) -> x * x
|
2009-12-23 19:42:18 -05:00
|
|
|
|
|
|
|
# Arrays:
|
2010-07-29 00:51:35 -04:00
|
|
|
list = [1, 2, 3, 4, 5]
|
2009-12-23 19:42:18 -05:00
|
|
|
|
|
|
|
# Objects:
|
2010-07-29 00:51:35 -04:00
|
|
|
math =
|
2009-12-23 19:42:18 -05:00
|
|
|
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-07-29 00:51:35 -04: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-11-21 12:38:27 -05:00
|
|
|
cubes = (math.cube num for num in list)
|