@walts81/linq-ts
Version:
Typescript/Javascript LINQ implementation library
21 lines (20 loc) • 565 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.first = void 0;
const _common_1 = require("./_common");
Array.prototype.first = first;
function first(expression) {
const length = this.length;
if (length === 0)
throw new _common_1.EmptyArrayException();
if (!expression)
return this[0];
for (let i = 0; i < length; i++) {
const item = this[i];
if (expression(item, i)) {
return item;
}
}
throw new _common_1.NoMatchException();
}
exports.first = first;