read


read
or learn more

Pointless programming in JavaScript

Apr 10, 2013 one comment

Using Underscore and Lemonad, how could you write a run-length encoder/decoder without ever referencing a function parameter? One way: var S = [‘a’, ‘a’, ‘a’, ‘a’, ‘b’, ‘c’, ‘c’, ‘a’, ‘a’, ‘d’, ‘e’, ‘e’, ‘e’, ‘e’]; var pack = L.partial1(L.partitionBy, _.identity); pack(S); //=> [[‘a’, ‘a’, ‘a’, ‘a’], [‘b’] …] var rle = _.compose( L.partial1(L.flip(_.map), L.juxt(L.plucker(‘length’), […]

Recursion is a low-level operation

Mar 9, 2011 some comments

Yesterday I demonstrated how to transform a mundane recursive function into a tail recursive function. However, I received some flak for that post because there are better ways to implement run-length encoding with Clojure. While certainly true, I think some of my critics1 missed the point of the exercise. ;-) Having said that; their points […]

Continue