-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpunctuate.coffee
51 lines (43 loc) · 934 Bytes
/
punctuate.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
_ = require 'underscore'
fs = require 'fs'
nums = [
'+[]'
'+!![]'
'-~!![]'
'-~-~!![]'
'-~-~-~!![]'
'-~-~-~-~!![]'
'-~-~!![]<<!![]'
'-~-~-~-~-~-~!![]'
'-~-~-~!![]<<!![]'
'-~-~!![]*-~-~!![]'
]
words =
'false' : '[]+![]'
'true' : '[]+!![]'
'undefined' : '[]+[][+[]]'
'Infinity' : '[]+!![]/+[]'
'[object Object]' : '[]+{}'
'NaN' : '[]+{}/!![]'
letter = (l) ->
best = _.reduce (Object.keys words), (m, n) ->
ndx = n.indexOf(l)
total = ndx + words[n].length
if ndx > -1
if total < m[0]
[total, ndx, words[n]]
else m
else m
, [Infinity, '']
if best[0] is Infinity
"'\\u#{('0000' + l.charCodeAt(0).toString(16)).substr - 4}'"
else
"(#{best[2]})[#{nums[best[1]]}]"
stringit = (str) ->
_.map str, letter
.join '+'
word = stringit 'js is dead cool'
console.log word
console.log word.length
console.log eval word
fs.writeFileSync 'output.txt', word