I want to implement a foldRight method with multiple reducer functions
Array.prototype.foldRight = function(f, acc){
if(this.length == 0){
return null;
}
else {
const head = this[0];
const tail = this.slice(1);
return foldRight(f(acc, head), tail);
}
};
But im still new to javascript, am I using the Array.prototype right to add an own method to the Array class? And why doesn’t it work when im testing it with exampleArray.foldRight((a,b)=>b+a) etc?