mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Move _.pluck to the Arrays category.
Former-commit-id: a3ba36c1c320c8685c25fcb0bbe16ba2baeb6731
This commit is contained in:
2
build.js
2
build.js
@@ -117,7 +117,7 @@
|
|||||||
'once': [],
|
'once': [],
|
||||||
'partial': [],
|
'partial': [],
|
||||||
'pick': [],
|
'pick': [],
|
||||||
'pluck': ['createIterator'],
|
'pluck': [],
|
||||||
'range': [],
|
'range': [],
|
||||||
'reduce': ['createIterator'],
|
'reduce': ['createIterator'],
|
||||||
'reduceRight': ['keys'],
|
'reduceRight': ['keys'],
|
||||||
|
|||||||
61
lodash.js
61
lodash.js
@@ -333,7 +333,7 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Reusable iterator options for `map`, `pluck`, and `values` */
|
/** Reusable iterator options for `map` and `values` */
|
||||||
var mapIteratorOptions = {
|
var mapIteratorOptions = {
|
||||||
'init': '',
|
'init': '',
|
||||||
'exit': 'if (!collection) return []',
|
'exit': 'if (!collection) return []',
|
||||||
@@ -710,34 +710,6 @@
|
|||||||
*/
|
*/
|
||||||
var map = createIterator(baseIteratorOptions, mapIteratorOptions);
|
var map = createIterator(baseIteratorOptions, mapIteratorOptions);
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the value of a specified property from all values in a `collection`.
|
|
||||||
*
|
|
||||||
* @static
|
|
||||||
* @memberOf _
|
|
||||||
* @category Collections
|
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
|
||||||
* @param {String} property The property to pluck.
|
|
||||||
* @returns {Array} Returns a new array of property values.
|
|
||||||
* @example
|
|
||||||
*
|
|
||||||
* var stooges = [
|
|
||||||
* { 'name': 'moe', 'age': 40 },
|
|
||||||
* { 'name': 'larry', 'age': 50 },
|
|
||||||
* { 'name': 'curly', 'age': 60 }
|
|
||||||
* ];
|
|
||||||
*
|
|
||||||
* _.pluck(stooges, 'name');
|
|
||||||
* // => ['moe', 'larry', 'curly']
|
|
||||||
*/
|
|
||||||
var pluck = createIterator(mapIteratorOptions, {
|
|
||||||
'args': 'collection, property',
|
|
||||||
'inLoop': {
|
|
||||||
'array': 'result[index] = collection[index][property]',
|
|
||||||
'object': 'result.push(collection[index][property])'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boils down a `collection` to a single value. The initial state of the
|
* Boils down a `collection` to a single value. The initial state of the
|
||||||
* reduction is `accumulator` and each successive step of it should be returned
|
* reduction is `accumulator` and each successive step of it should be returned
|
||||||
@@ -1418,6 +1390,37 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the value of a specified property from all elements in `array`.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Arrays
|
||||||
|
* @param {Array} array The array to iterate over.
|
||||||
|
* @param {String} property The property to pluck.
|
||||||
|
* @returns {Array} Returns a new array of property values.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var stooges = [
|
||||||
|
* { 'name': 'moe', 'age': 40 },
|
||||||
|
* { 'name': 'larry', 'age': 50 },
|
||||||
|
* { 'name': 'curly', 'age': 60 }
|
||||||
|
* ];
|
||||||
|
*
|
||||||
|
* _.pluck(stooges, 'name');
|
||||||
|
* // => ['moe', 'larry', 'curly']
|
||||||
|
*/
|
||||||
|
function pluck(array, property) {
|
||||||
|
var index = -1,
|
||||||
|
length = array.length,
|
||||||
|
result = Array(length);
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
result[index] = array[index][property];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of numbers (positive and/or negative) progressing from
|
* Creates an array of numbers (positive and/or negative) progressing from
|
||||||
* `start` up to but not including `stop`. This method is a port of Python's
|
* `start` up to but not including `stop`. This method is a port of Python's
|
||||||
|
|||||||
Reference in New Issue
Block a user