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.

28 lines
562 B

4 years ago
'use strict';
var _require = require('../helpers/is'),
isFunction = _require.isFunction;
module.exports = function last(fn, defaultValue) {
var items = this.items;
if (isFunction(fn)) {
items = this.filter(fn).all();
}
if (Array.isArray(items) && !items.length || !Object.keys(items).length) {
if (isFunction(defaultValue)) {
return defaultValue();
}
return defaultValue;
}
if (Array.isArray(items)) {
return items[items.length - 1];
}
var keys = Object.keys(items);
return items[keys[keys.length - 1]];
};