You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
323 B
JavaScript

"use strict";
// Kinda like `find`, but the ?? edition - evaluates items until one produces a not-nullish result
module.exports = function firstValue(iterable, predicate) {
let i = 0;
for (let value of iterable) {
let found = predicate(value, i, iterable);
if (found != null) {
return found;
}
i++;
}
};