mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Optimize _.pluck for modern environments.
Former-commit-id: 1a6bbb9866b8ac20faaa707be5f33814579e1df8
This commit is contained in:
13
dist/lodash.underscore.js
vendored
13
dist/lodash.underscore.js
vendored
@@ -2057,7 +2057,18 @@
|
||||
* _.pluck(stooges, 'name');
|
||||
* // => ['moe', 'larry']
|
||||
*/
|
||||
var pluck = map;
|
||||
function pluck(collection, property) {
|
||||
var index = -1,
|
||||
length = collection ? collection.length : 0;
|
||||
|
||||
if (typeof length == 'number') {
|
||||
var result = Array(length);
|
||||
while (++index < length) {
|
||||
result[index] = collection[index][property]
|
||||
}
|
||||
}
|
||||
return result || map(collection, property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces a `collection` to a value that is the accumulated result of running
|
||||
|
||||
Reference in New Issue
Block a user