Can a predicate be an object in JavaScript (as in C++)?
For example, is it possible to find the index of an element in an array (with arr.findIndex(pred)) with a predicate like this?
class Predicate
{
constructor()
{
this.sum = 0;
}
evaluate(elem)
{
this.sum += elem;
return sum > 25;
}
}
const pred = new Predicate();
const index = arr.findIndex(pred);
EDIT1: If no, what is the easiest way to find the index of an element that makes the sum of it and all the previous elements exceed 25?