UNPKG

@walts81/linq-ts

Version:

Typescript/Javascript LINQ implementation library

17 lines (16 loc) 532 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.lastOrDefault = void 0; Array.prototype.lastOrDefault = lastOrDefault; function lastOrDefault(expression, defaultValue = null) { const length = this.length; if (!expression) return length > 0 ? this[length - 1] : defaultValue; for (let i = length - 1; i >= 0; i--) { const item = this[i]; if (expression(item, i)) return item; } return defaultValue; } exports.lastOrDefault = lastOrDefault;