4308 |
| - n++; | 4309 |
| - } |
4310 |
| - } else { |
4311 |
| - n = callback; |
4312 |
| - if (n == null || thisArg) { |
4313 |
| - return array[0]; |
4314 |
| - } |
| 4306 | + if (typeof callback != 'number' && callback != null) { |
| 4307 | + var index = -1; |
| 4308 | + callback = lodash.createCallback(callback, thisArg, 3); |
| 4309 | + while (++index < length && callback(array[index], index, array)) { |
| 4310 | + n++; |
| 4311 | + } |
| 4312 | + } else { |
| 4313 | + n = callback; |
| 4314 | + if (n == null || thisArg) { |
| 4315 | + return array ? array[0] : undefined; |
4315 | 4316 | }
|
4316 |
| - return slice(array, 0, nativeMin(nativeMax(0, n), length)); |
4317 | 4317 | }
|
| 4318 | + return slice(array, 0, nativeMin(nativeMax(0, n), length)); |
4318 | 4319 | }
|
4319 | 4320 |
|
4320 | 4321 | /**
|
|
4362 | 4363 | // juggle arguments
|
4363 | 4364 | if (typeof isShallow != 'boolean' && isShallow != null) {
|
4364 | 4365 | thisArg = callback;
|
4365 |
| - callback = !(thisArg && thisArg[isShallow] === array) ? isShallow : undefined; |
| 4366 | + callback = !(thisArg && thisArg[isShallow] === array) ? isShallow : null; |
4366 | 4367 | isShallow = false;
|
4367 | 4368 | }
|
4368 | 4369 | if (callback != null) {
|
|
4462 | 4463 | * // => [{ 'name': 'banana', 'type': 'fruit' }]
|
4463 | 4464 | */
|
4464 | 4465 | function initial(array, callback, thisArg) {
|
4465 |
| - if (!array) { |
4466 |
| - return []; |
4467 |
| - } |
4468 | 4466 | var n = 0,
|
4469 |
| - length = array.length; |
| 4467 | + length = array ? array.length : 0; |
4470 | 4468 |
|
4471 | 4469 | if (typeof callback != 'number' && callback != null) {
|
4472 | 4470 | var index = length;
|
|
4595 | 4593 | * // => [{ 'name': 'beet', 'type': 'vegetable' }, { 'name': 'carrot', 'type': 'vegetable' }]
|
4596 | 4594 | */
|
4597 | 4595 | function last(array, callback, thisArg) {
|
4598 |
| - if (array) { |
4599 |
| - var n = 0, |
4600 |
| - length = array.length; |
| 4596 | + var n = 0, |
| 4597 | + length = array ? array.length : 0; |
4601 | 4598 |
|
4602 |
| - if (typeof callback != 'number' && callback != null) { |
4603 |
| - var index = length; |
4604 |
| - callback = lodash.createCallback(callback, thisArg, 3); |
4605 |
| - while (index-- && callback(array[index], index, array)) { |
4606 |
| - n++; |
4607 |
| - } |
4608 |
| - } else { |
4609 |
| - n = callback; |
4610 |
| - if (n == null || thisArg) { |
4611 |
| - return array[length - 1]; |
4612 |
| - } |
| 4599 | + if (typeof callback != 'number' && callback != null) { |
| 4600 | + var index = length; |
| 4601 | + callback = lodash.createCallback(callback, thisArg, 3); |
| 4602 | + while (index-- && callback(array[index], index, array)) { |
| 4603 | + n++; |
| 4604 | + } |
| 4605 | + } else { |
| 4606 | + n = callback; |
| 4607 | + if (n == null || thisArg) { |
| 4608 | + return array ? array[length - 1] : undefined; |
4613 | 4609 | }
|
4614 |
| - return slice(array, nativeMax(0, length - n)); |
4615 | 4610 | }
|
| 4611 | + return slice(array, nativeMax(0, length - n)); |
4616 | 4612 | }
|
4617 | 4613 |
|
4618 | 4614 | /**
|
|
4990 | 4986 | // juggle arguments
|
4991 | 4987 | if (typeof isSorted != 'boolean' && isSorted != null) {
|
4992 | 4988 | thisArg = callback;
|
4993 |
| - callback = !(thisArg && thisArg[isSorted] === array) ? isSorted : undefined; |
| 4989 | + callback = !(thisArg && thisArg[isSorted] === array) ? isSorted : null; |
4994 | 4990 | isSorted = false;
|
4995 | 4991 | }
|
4996 | 4992 | if (callback != null) {
|
|
5972 | 5968 | * // => 'nonsense'
|
5973 | 5969 | */
|
5974 | 5970 | function result(object, property) {
|
5975 |
| - var value = object ? object[property] : undefined; |
5976 |
| - return isFunction(value) ? object[property]() : value; |
| 5971 | + if (object) { |
| 5972 | + var value = object[property]; |
| 5973 | + return isFunction(value) ? object[property]() : value; |
| 5974 | + } |
5977 | 5975 | }
|
5978 | 5976 |
|
5979 | 5977 | /**
|
|
0 commit comments