array lenght by catamorhism
by dimitrs_papadimitriou
HTML
<script src="https://rawgit.com/eu81273/jsfiddle-console/master/console.js"></script>
JavaScript
Array.prototype.matchWith = function (pattern) {
return this.length == 0 ?
pattern.empty() :
pattern.concat(this[0], this.slice(1));// informed decesion not to clone
}
const head = array=>array.matchWith({
empty: () => null,
concat: (v, r) => v
});
console.log(head([1,2,3,4,5,6]));
const tail = array=>array.matchWith({
empty: () => null,
concat: (v, r) => r
});
console.log(tail([1,2,3,4,5,6]));