> head extracts the first element of a list, which must be non-empty.
Those functions operate on lists. I think it should read as follows.
const head = (xs) => xs[0];
const last = (xs) => xs[xs.length-1];
const tail = (xs) => xs.slice(1);
const init = (xs) => xs.slice(0, -1);
Am I missing something?For some reason, the original author decided the arguments themselves were the "list" to operate on which is indeed a bit weird and non idiomatic.
Re:Haskell in ES6: Part 1
by heydenberk on Saturday November 14, 2015 @10:24AM
(#10565935)
You can also avoid reversing the arrays before reducing them by calling the method `reduceRight`.
- `f.apply(null, args)` calls can be replaced with `f(...args)`
- Your head function returns the first argument while your last function returns an array containing the last argument. I'd rewrite those functions as:
(Unfortunately it seems the rest operator can only appear as the last argument.)- Why put everything on the prototype? It doesn't seem necessary since you are not using the `this` keyword. I would just stick the `export` keyword in front of functions to be exported.
Looking forward to part 2.