mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Simplify _.initial.
This commit is contained in:
17
lodash.js
17
lodash.js
@@ -3114,22 +3114,9 @@
|
||||
* _.initial([1, 2, 3]);
|
||||
* // => [1, 2]
|
||||
*/
|
||||
function initial(array, predicate, thisArg) {
|
||||
function initial(array) {
|
||||
var length = array ? array.length : 0;
|
||||
|
||||
if (typeof predicate != 'number' && predicate != null) {
|
||||
var index = length,
|
||||
n = 0;
|
||||
|
||||
predicate = lodash.callback(predicate, thisArg, 3);
|
||||
while (index-- && predicate(array[index], index, array)) {
|
||||
n++;
|
||||
}
|
||||
} else {
|
||||
n = (predicate == null || thisArg) ? 1 : predicate;
|
||||
}
|
||||
n = length - (n || 0);
|
||||
return slice(array, 0, n < 0 ? 0 : n);
|
||||
return slice(array, 0, length ? length - 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user