4 ms·
While I agree with the sentiment with comparing apples to apples, I happened to notice this can be expressed nearly as elegantly in CoffeeScript: list_min
by athenot 7y ago
While I agree with the sentiment with comparing apples to apples, I happened to notice this can be expressed nearly as elegantly in CoffeeScript:
list_min = (l) -> reduce min, l
With the definitions being:
min = (a, b) -> if a < b then a else b
reduce = (op, l) => switch
when l.length is 0 then throw "reduce: empty list"
when l.length is 1 then l[0]
else reduce op, [(op l[0], l[1]), l[2..]].flat()