Skip to content

Instantly share code, notes, and snippets.

# Money -> Number
money-sum = (money) -> money |> obj-to-pairs |> map apply (*) |> sum
# Number -> Money
to-money = (sum) ->
sum-places = "0000#sum" |> chars |> reverse |> map parse-int
10000: floor sum / 10000
5000: if sum-places.3 >= 5 then 1 else 0
1000: if sum-places.3 >= 5 then sum-places.3 - 5 else sum-places.3
500: if sum-places.2 >= 5 then 1 else 0
@AyaMorisawa
AyaMorisawa / lota.md
Created March 23, 2015 04:50
LiveScript Operators Type Annotation

Number

Standard Math

(+) :: Number -> Number -> Number
(-) :: Number -> Number -> Number
@AyaMorisawa
AyaMorisawa / !Str.ls
Created February 25, 2015 14:25
Str.ls
Str.ls
List.ls
@AyaMorisawa
AyaMorisawa / !Num.ls
Last active August 29, 2015 14:16
Num.ls
Num.ls
Y = (r) -> ((f) -> f f)((f) -> r (x) -> f f x)
usersA = [ id: 4872, name: 'alice' ]
usersB = [ id: 2849, name: 'bob' ]
users = (usersA ++ usersB) |> sort-by (.id)
console.log users
@AyaMorisawa
AyaMorisawa / clone.ls
Created February 11, 2015 13:31
Clone in LiveScript
a = name: 'alice'
console.log a.name
b = ^^a
console.log b.name
b.name = 'bob'
console.log b.name
console.log a.name
app = express!
server = http.createServer app
io = require \socket.io .listen do
server
origins: 'hoge.jp:*'
@AyaMorisawa
AyaMorisawa / project-eular-002.ls
Created February 6, 2015 13:29
Project Eular 002 LiveScript
global <<< require \prelude-ls
gen-list-while = (f, max) ->
list = []
i = 0
while f(i) < max then f(i++) |> list.push
list
memoize = (memo, f) -> shell = (n) -> memo[n] ?= f shell, n