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
}
Array.prototype.lenght1=function(){
return this.matchWith({
empty: () => 0,
concat: (v, r) => 1 + r.lenght1()
});
}
var lenght = [1, 2, 3, 4, 5, 2].lenght1()
console.log(lenght);