🎚 Window-sliding insertion algorithm in JavaScript
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
443 B

class Deck extends Array {
7 years ago
recurse (fn) {
let index = 0;
const call = (arr, acc = []) => {
if(arr[0]) {
const res = fn(index++, arr[0]);
return call(arr.slice(1), [ res, ...acc ]);
}
return acc;
};
return call(this);
}
findIndexAfter(index, predicate) {
const self = this;
let i = index + 1;
while(i < self.length) {
if(predicate(self[i])) return i;
i++;
}
return -1;
}
};
module.exports = Deck;