* Gets the last element or last `n` elements of an array. If a callback is * provided elements at the end of the array are returned as long as the * callback returns truey. The callback is bound to `thisArg` and invoked * with three arguments; (value, index, array). * * If a
(array, callback, thisArg)
| 39722 | * // => [{ 'name': 'pebbles', 'blocked': true, 'employer': 'na' }] |
| 39723 | */ |
| 39724 | function last(array, callback, thisArg) { |
| 39725 | var n = 0, |
| 39726 | length = array ? array.length : 0; |
| 39727 | |
| 39728 | if (typeof callback != 'number' && callback != null) { |
| 39729 | var index = length; |
| 39730 | callback = lodash.createCallback(callback, thisArg, 3); |
| 39731 | while (index-- && callback(array[index], index, array)) { |
| 39732 | n++; |
| 39733 | } |
| 39734 | } else { |
| 39735 | n = callback; |
| 39736 | if (n == null || thisArg) { |
| 39737 | return array ? array[length - 1] : undefined; |
| 39738 | } |
| 39739 | } |
| 39740 | return slice(array, nativeMax(0, length - n)); |
| 39741 | } |
| 39742 | |
| 39743 | /** |
| 39744 | * Gets the index at which the last occurrence of `value` is found using strict |
no test coverage detected