Update _.reduce and _.transform object iteration doc example. [ci skip]

This commit is contained in:
John-David Dalton
2015-08-09 00:09:17 -07:00
parent 1647c4deab
commit b4edf122f6

View File

@@ -6262,11 +6262,11 @@
* }); * });
* // => 3 * // => 3
* *
* _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) { * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
* result[key] = n * 3; * (result[value] || (result[value] = [])).push(key);
* return result; * return result;
* }, {}); * }, {});
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed) * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
*/ */
function reduce(collection, iteratee, accumulator) { function reduce(collection, iteratee, accumulator) {
var initFromArray = arguments.length < 3; var initFromArray = arguments.length < 3;
@@ -9469,10 +9469,10 @@
* }); * });
* // => [4, 9] * // => [4, 9]
* *
* _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) { * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
* result[key] = n * 3; * (result[value] || (result[value] = [])).push(key);
* }); * });
* // => { 'a': 3, 'b': 6 } * // => { '1': ['a', 'c'], '2': ['b'] }
*/ */
function transform(object, iteratee, accumulator) { function transform(object, iteratee, accumulator) {
var isArr = isArray(object) || isTypedArray(object); var isArr = isArray(object) || isTypedArray(object);