Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Eat lunch.
- eat = (food) -> "#{food} eaten."
- eat food for food in ['toast', 'cheese', 'wine']
- # Fine five course dining.
- courses = ['greens', 'caviar', 'truffles', 'roast', 'cake']
- menu = (i, dish) -> "Menu Item #{i}: #{dish}"
- menu i + 1, dish for dish, i in courses
- # Health conscious meal.
- foods = ['broccoli', 'spinach', 'chocolate']
- console.log (eat food for food in foods when food isnt 'chocolate'
- #------
- [1..10].filter (x) -> x%2
- #------
- console.log i for i in [10..0]
- #------
- for i in [10..0]
- console.log i
- #------
- for i in [10..0] then console.log i
- #------
- data = [ 1, 2, 3, "a", "b", "c", 2, 3, 4, "b", "c", "d" ]
- set = []
- set.push i for i in data when not (i in set)
- console.log data
- console.log set
- #------
- keys = ['a','b','c']
- values = [1,2,3]
- map = {}
- map[key] = values[i] for key, i in keys
- #---------
- sameOcc = []
- nums1 = [3,1,2,2,1]
- nums2 = [2,2,3]
- sameOcc.push i for i in nums1 when i in nums1 and i in nums2
- console.log sameOcc
- #[3,2,2]
- #---------
- sumOfSquares = ( list ) ->
- list.reduce (( sum, x ) -> sum + x ), 0
- sumOfSquares [1,2,3,4]
- #10
- #---------
- class Foo
- @staticMethod: -> 'Bar'
- instanceMethod: -> 'Baz'
- foo = new Foo
- foo.instanceMethod() #=> 'Baz'
- Foo.staticMethod() #=> 'Bar'
- #---------
- launch() if ignition is on
- #---------
- volume = 10 if band isnt SpinalTap
- #---------
- letTheWildRumpusBegin() unless answer is no
- #---------
- if car.speed < limit then accelerate()
- #---------
- winner = yes if pick in [47, 92, 13]
- #---------
- print inspect "My name is #{@name}"
- #---------
- eldest = if 24 > 21 then "Liz" else "Ike"
- #---------
- for a from b _EQUIVALENT_ for (a of b)
- #---------
- a ? b returns a if a is in scope and a != null; otherwise, b
- #---------
- sleep = (ms) ->
- new Promise (resolve) ->
- window.setTimeout resolve, ms
- say = (text) ->
- window.speechSynthesis.cancel()
- window.speechSynthesis.speak new SpeechSynthesisUtterance text
- countdown = (seconds) ->
- for i in [seconds..1]
- say i
- await sleep 1000 # wait one second
- say "Blastoff!"
- countdown 3
- #---------
- ages = for child, age of yearsOld
- "#{child} is #{age}"
- # => [ 'max is 10', 'ida is 9', 'tim is 11' ]
- #---------
- #---------
- #---------
- #---------
- #---------
- #---------
- #---------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement