2009-12-24 00:42:18 +00:00
|
|
|
# Assignment:
|
2010-07-29 04:51:35 +00:00
|
|
|
number = 42
|
|
|
|
opposite = true
|
2009-12-24 00:42:18 +00:00
|
|
|
|
|
|
|
# Conditions:
|
2010-07-29 04:51:35 +00:00
|
|
|
number = -42 if opposite
|
2009-12-24 00:42:18 +00:00
|
|
|
|
|
|
|
# Functions:
|
2010-07-29 04:51:35 +00:00
|
|
|
square = (x) -> x * x
|
2009-12-24 00:42:18 +00:00
|
|
|
|
|
|
|
# Arrays:
|
2010-07-29 04:51:35 +00:00
|
|
|
list = [1, 2, 3, 4, 5]
|
2009-12-24 00:42:18 +00:00
|
|
|
|
|
|
|
# Objects:
|
2010-07-29 04:51:35 +00:00
|
|
|
math =
|
2009-12-24 00:42:18 +00:00
|
|
|
root: Math.sqrt
|
|
|
|
square: square
|
2010-01-26 15:52:05 +00:00
|
|
|
cube: (x) -> x * square x
|
2009-12-24 00:42:18 +00:00
|
|
|
|
2010-01-05 05:34:18 +00:00
|
|
|
# Splats:
|
2010-07-29 04:51:35 +00:00
|
|
|
race = (winner, runners...) ->
|
2010-01-25 05:14:00 +00:00
|
|
|
print winner, runners
|
2010-01-05 05:34:18 +00:00
|
|
|
|
|
|
|
# Existence:
|
2010-01-25 05:14:00 +00:00
|
|
|
alert "I knew it!" if elvis?
|
2010-01-05 05:34:18 +00:00
|
|
|
|
2009-12-24 00:42:18 +00:00
|
|
|
# Array comprehensions:
|
2010-11-21 17:38:27 +00:00
|
|
|
cubes = (math.cube num for num in list)
|