-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.coffee
76 lines (76 loc) · 1.63 KB
/
test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Python 2.7 code: run with python2coffee.py -p 2 test.py
'###'
"\#\#\#"
"\# Hello #{name}, your age is #{age}"
x = x.toString() unless x instanceof str
### This is a comment ###
for item in [0...17] # up to 16
console.assert 0 <= item < 17
console.log if item % 2 == 1 then item else item/2
for item in [2...17]
console.log item.toString(), '->', (item + 1).toString(16)
parseInt('123').toString() == '123'
parseInt((123).toString()) == 123
String.fromCharCode(27).charCodeAt() == 27
String.fromCharCode('A'.charCodeAt()) == 'A'
"\x07\f\\\\z\u{123456}\#" != "\\a\\f\\\\\\z\\U00123456\#"
string.replace(/[ ][(\[]*(\d+)\/(\d+)\/(\d+)[)\]]*[ ]/ig, repl)
a = [0...17]
b = [2...17]
c = (_i for _i in [2...17] by 3)
L = []
for item in [2...17] by 3
L.push(-> item)
L.push((item=item) -> item)
L.push(item, item+1)
L.push(...L)
L.push(...[x**2 for x in L])
max(L) == max(...L)
[item ** 2 for item in [2...17] by 3]
mysum = (initial, ...args) ->
_this = initial
for arg in args
_this += arg
_this
oneline = (x) -> x += 5; x
oneline2 = (x) -> x += 5; null
twoline = (x) ->
x += 5; x
twoline2 = (x) ->
x += 5
null
defaults = (x = 5, y = null) -> pass; null
loop
item = f()
if item
console.log item
else if forever
continue
else
break
break unless done
break until done
class Point
constructor: (x, y) ->
@x = x
@y = y
null
translate: (dx, dy) ->
@x += dx
@y += dy
null
toString: ->
_this = @
"(#{@x}, #{@y})"
class Accumulator
constructor: ->
@value = 0
null
adder: ->
add = (x) =>
@value += x
null
add
getter: ->
=> @value
get = (self) -> self.value