ui
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
'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]];
|
||||
};
|
||||
Reference in New Issue
Block a user