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