mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Fix doc typos.
This commit is contained in:
108
lodash.js
108
lodash.js
@@ -2124,11 +2124,11 @@
|
|||||||
* @returns {string|undefined} Returns the key of the found element, else `undefined`.
|
* @returns {string|undefined} Returns the key of the found element, else `undefined`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var characters = [
|
* var characters = {
|
||||||
* { 'name': 'barney', 'age': 36, 'blocked': false },
|
* 'barney': { 'age': 36, 'blocked': false },
|
||||||
* { 'name': 'fred', 'age': 40, 'blocked': true },
|
* 'fred': { 'age': 40, 'blocked': true },
|
||||||
* { 'name': 'pebbles', 'age': 1, 'blocked': false }
|
* 'pebbles': { 'age': 1, 'blocked': false }
|
||||||
* ];
|
* };
|
||||||
*
|
*
|
||||||
* _.findKey(characters, function(chr) {
|
* _.findKey(characters, function(chr) {
|
||||||
* return chr.age < 40;
|
* return chr.age < 40;
|
||||||
@@ -2177,11 +2177,11 @@
|
|||||||
* @returns {string|undefined} Returns the key of the found element, else `undefined`.
|
* @returns {string|undefined} Returns the key of the found element, else `undefined`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var characters = [
|
* var characters = {
|
||||||
* { 'name': 'barney', 'age': 36, 'blocked': true },
|
* 'barney': { 'age': 36, 'blocked': true },
|
||||||
* { 'name': 'fred', 'age': 40, 'blocked': false },
|
* 'fred': { 'age': 40, 'blocked': false },
|
||||||
* { 'name': 'pebbles', 'age': 1, 'blocked': true }
|
* 'pebbles': { 'age': 1, 'blocked': true }
|
||||||
* ];
|
* };
|
||||||
*
|
*
|
||||||
* _.findLastKey(characters, function(chr) {
|
* _.findLastKey(characters, function(chr) {
|
||||||
* return chr.age < 40;
|
* return chr.age < 40;
|
||||||
@@ -3214,7 +3214,7 @@
|
|||||||
* else `false`.
|
* else `false`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.every([true, 1, null, 'yes'], Boolean);
|
* _.every([true, 1, null, 'yes']);
|
||||||
* // => false
|
* // => false
|
||||||
*
|
*
|
||||||
* var characters = [
|
* var characters = [
|
||||||
@@ -3650,7 +3650,7 @@
|
|||||||
*
|
*
|
||||||
* // using "_.pluck" callback shorthand
|
* // using "_.pluck" callback shorthand
|
||||||
* _.map(characters, 'name');
|
* _.map(characters, 'name');
|
||||||
* // => ['fred', 'barney']
|
* // => ['barney', 'fred']
|
||||||
*/
|
*/
|
||||||
function map(collection, callback, thisArg) {
|
function map(collection, callback, thisArg) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
@@ -3703,12 +3703,12 @@
|
|||||||
* { 'name': 'fred', 'age': 40 }
|
* { 'name': 'fred', 'age': 40 }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* _.max(characters, function(stooge) { return stooge.age; });
|
* _.max(characters, function(chr) { return chr.age; });
|
||||||
* // => { 'name': 'barney', 'age': 36 };
|
* // => { 'name': 'fred', 'age': 40 };
|
||||||
*
|
*
|
||||||
* // using "_.pluck" callback shorthand
|
* // using "_.pluck" callback shorthand
|
||||||
* _.max(characters, 'age');
|
* _.max(characters, 'age');
|
||||||
* // => { 'name': 'barney', 'age': 36 };
|
* // => { 'name': 'fred', 'age': 40 };
|
||||||
*/
|
*/
|
||||||
function max(collection, callback, thisArg) {
|
function max(collection, callback, thisArg) {
|
||||||
var computed = -Infinity,
|
var computed = -Infinity,
|
||||||
@@ -3773,12 +3773,12 @@
|
|||||||
* { 'name': 'fred', 'age': 40 }
|
* { 'name': 'fred', 'age': 40 }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* _.min(characters, function(stooge) { return stooge.age; });
|
* _.min(characters, function(chr) { return chr.age; });
|
||||||
* // => { 'name': 'fred', 'age': 40 };
|
* // => { 'name': 'barney', 'age': 36 };
|
||||||
*
|
*
|
||||||
* // using "_.pluck" callback shorthand
|
* // using "_.pluck" callback shorthand
|
||||||
* _.min(characters, 'age');
|
* _.min(characters, 'age');
|
||||||
* // => { 'name': 'fred', 'age': 40 };
|
* // => { 'name': 'barney', 'age': 36 };
|
||||||
*/
|
*/
|
||||||
function min(collection, callback, thisArg) {
|
function min(collection, callback, thisArg) {
|
||||||
var computed = Infinity,
|
var computed = Infinity,
|
||||||
@@ -3828,7 +3828,7 @@
|
|||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* _.pluck(characters, 'name');
|
* _.pluck(characters, 'name');
|
||||||
* // => ['fred', 'barney']
|
* // => ['barney', 'fred']
|
||||||
*/
|
*/
|
||||||
var pluck = map;
|
var pluck = map;
|
||||||
|
|
||||||
@@ -3951,7 +3951,7 @@
|
|||||||
* // => [{ 'name': 'barney', 'age': 36, 'blocked': false }]
|
* // => [{ 'name': 'barney', 'age': 36, 'blocked': false }]
|
||||||
*
|
*
|
||||||
* // using "_.where" callback shorthand
|
* // using "_.where" callback shorthand
|
||||||
* _.reject(characters, { 'age': 40 });
|
* _.reject(characters, { 'age': 36 });
|
||||||
* // => [{ 'name': 'fred', 'age': 40, 'blocked': true }]
|
* // => [{ 'name': 'fred', 'age': 40, 'blocked': true }]
|
||||||
*/
|
*/
|
||||||
function reject(collection, callback, thisArg) {
|
function reject(collection, callback, thisArg) {
|
||||||
@@ -4205,12 +4205,12 @@
|
|||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var characters = [
|
* var characters = [
|
||||||
* { 'name': 'barney', 'age': 30, 'pets': ['hoppy'] },
|
* { 'name': 'barney', 'age': 36, 'pets': ['hoppy'] },
|
||||||
* { 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }
|
* { 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* _.where(characters, { 'age': 30 });
|
* _.where(characters, { 'age': 36 });
|
||||||
* // => [{ 'name': 'barney', 'age': 30, 'pets': ['hoppy'] }]
|
* // => [{ 'name': 'barney', 'age': 36, 'pets': ['hoppy'] }]
|
||||||
*
|
*
|
||||||
* _.where(characters, { 'pets': ['dino'] });
|
* _.where(characters, { 'pets': ['dino'] });
|
||||||
* // => [{ 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }]
|
* // => [{ 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }]
|
||||||
@@ -4436,14 +4436,14 @@
|
|||||||
* // => [1, 2]
|
* // => [1, 2]
|
||||||
*
|
*
|
||||||
* var characters = [
|
* var characters = [
|
||||||
* { 'name': 'barney', 'age': 36, 'blocked': true, 'employer': 'slate' },
|
* { 'name': 'barney', 'blocked': true, 'employer': 'slate' },
|
||||||
* { 'name': 'fred', 'age': 40, 'blocked': false, 'employer': 'slate' },
|
* { 'name': 'fred', 'blocked': false, 'employer': 'slate' },
|
||||||
* { 'name': 'pebbles', 'age': 1, 'blocked': true, 'employer': 'na' }
|
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* // using "_.pluck" callback shorthand
|
* // using "_.pluck" callback shorthand
|
||||||
* _.first(characters, 'blocked');
|
* _.first(characters, 'blocked');
|
||||||
* // => [{ 'name': 'barney', 'age': 36, 'blocked': true, 'employer': 'slate' }]
|
* // => [{ 'name': 'barney', 'blocked': true, 'employer': 'slate' }]
|
||||||
*
|
*
|
||||||
* // using "_.where" callback shorthand
|
* // using "_.where" callback shorthand
|
||||||
* _.pluck(_.first(characters, { 'employer': 'slate' }), 'name');
|
* _.pluck(_.first(characters, { 'employer': 'slate' }), 'name');
|
||||||
@@ -4593,24 +4593,19 @@
|
|||||||
* });
|
* });
|
||||||
* // => [1]
|
* // => [1]
|
||||||
*
|
*
|
||||||
* var food = [
|
* var characters = [
|
||||||
* { 'name': 'beet', 'organic': false },
|
* { 'name': 'barney', 'blocked': false, 'employer': 'slate' },
|
||||||
* { 'name': 'carrot', 'organic': true }
|
* { 'name': 'fred', 'blocked': true, 'employer': 'slate' },
|
||||||
|
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* // using "_.pluck" callback shorthand
|
* // using "_.pluck" callback shorthand
|
||||||
* _.initial(food, 'organic');
|
* _.initial(characters, 'blocked');
|
||||||
* // => [{ 'name': 'beet', 'organic': false }]
|
* // => [{ 'name': 'barney', 'blocked': false, 'employer': 'slate' }]
|
||||||
*
|
|
||||||
* var food = [
|
|
||||||
* { 'name': 'banana', 'type': 'fruit' },
|
|
||||||
* { 'name': 'beet', 'type': 'vegetable' },
|
|
||||||
* { 'name': 'carrot', 'type': 'vegetable' }
|
|
||||||
* ];
|
|
||||||
*
|
*
|
||||||
* // using "_.where" callback shorthand
|
* // using "_.where" callback shorthand
|
||||||
* _.initial(food, { 'type': 'vegetable' });
|
* _.pluck(_.initial(characters, { 'employer': 'na' }), 'name');
|
||||||
* // => [{ 'name': 'banana', 'type': 'fruit' }]
|
* // => ['barney', 'fred']
|
||||||
*/
|
*/
|
||||||
function initial(array, callback, thisArg) {
|
function initial(array, callback, thisArg) {
|
||||||
var n = 0,
|
var n = 0,
|
||||||
@@ -4724,9 +4719,9 @@
|
|||||||
* // => [2, 3]
|
* // => [2, 3]
|
||||||
*
|
*
|
||||||
* var characters = [
|
* var characters = [
|
||||||
* { 'name': 'barney', 'age': 36, 'blocked': false, 'employer': 'slate' },
|
* { 'name': 'barney', 'blocked': false, 'employer': 'slate' },
|
||||||
* { 'name': 'fred', 'age': 40, 'blocked': true, 'employer': 'slate' },
|
* { 'name': 'fred', 'blocked': true, 'employer': 'slate' },
|
||||||
* { 'name': 'pebbles', 'age': 1, 'blocked': true, 'employer': 'na' }
|
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* // using "_.pluck" callback shorthand
|
* // using "_.pluck" callback shorthand
|
||||||
@@ -4735,7 +4730,7 @@
|
|||||||
*
|
*
|
||||||
* // using "_.where" callback shorthand
|
* // using "_.where" callback shorthand
|
||||||
* _.last(characters, { 'employer': 'na' });
|
* _.last(characters, { 'employer': 'na' });
|
||||||
* // => [{ 'name': 'pebbles', 'age': 1, 'blocked': true, 'employer': 'na' }]
|
* // => [{ 'name': 'pebbles', 'blocked': true, 'employer': 'na' }]
|
||||||
*/
|
*/
|
||||||
function last(array, callback, thisArg) {
|
function last(array, callback, thisArg) {
|
||||||
var n = 0,
|
var n = 0,
|
||||||
@@ -4972,24 +4967,19 @@
|
|||||||
* });
|
* });
|
||||||
* // => [3]
|
* // => [3]
|
||||||
*
|
*
|
||||||
* var food = [
|
* var characters = [
|
||||||
* { 'name': 'banana', 'organic': true },
|
* { 'name': 'barney', 'blocked': true, 'employer': 'slate' },
|
||||||
* { 'name': 'beet', 'organic': false },
|
* { 'name': 'fred', 'blocked': false, 'employer': 'slate' },
|
||||||
|
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* // using "_.pluck" callback shorthand
|
* // using "_.pluck" callback shorthand
|
||||||
* _.rest(food, 'organic');
|
* _.pluck(_.rest(characters, 'blocked'), 'name');
|
||||||
* // => [{ 'name': 'beet', 'organic': false }]
|
* // => ['fred', 'pebbles']
|
||||||
*
|
|
||||||
* var food = [
|
|
||||||
* { 'name': 'apple', 'type': 'fruit' },
|
|
||||||
* { 'name': 'banana', 'type': 'fruit' },
|
|
||||||
* { 'name': 'beet', 'type': 'vegetable' }
|
|
||||||
* ];
|
|
||||||
*
|
*
|
||||||
* // using "_.where" callback shorthand
|
* // using "_.where" callback shorthand
|
||||||
* _.rest(food, { 'type': 'fruit' });
|
* _.rest(characters, { 'employer': 'slate' });
|
||||||
* // => [{ 'name': 'beet', 'type': 'vegetable' }]
|
* // => [{ 'name': 'pebbles', 'blocked': true, 'employer': 'na' }]
|
||||||
*/
|
*/
|
||||||
function rest(array, callback, thisArg) {
|
function rest(array, callback, thisArg) {
|
||||||
if (typeof callback != 'number' && callback != null) {
|
if (typeof callback != 'number' && callback != null) {
|
||||||
@@ -6483,14 +6473,14 @@
|
|||||||
*
|
*
|
||||||
* // without explicit chaining
|
* // without explicit chaining
|
||||||
* _(characters).first();
|
* _(characters).first();
|
||||||
* // => { 'name': 'fred', 'age': 40 }
|
* // => { 'name': 'barney', 'age': 36 }
|
||||||
*
|
*
|
||||||
* // with explicit chaining
|
* // with explicit chaining
|
||||||
* _(characters).chain()
|
* _(characters).chain()
|
||||||
* .first()
|
* .first()
|
||||||
* .pick('age')
|
* .pick('age')
|
||||||
* .value()
|
* .value()
|
||||||
* // => { 'age': 40 }
|
* // => { 'age': 36 }
|
||||||
*/
|
*/
|
||||||
function wrapperChain() {
|
function wrapperChain() {
|
||||||
this.__chain__ = true;
|
this.__chain__ = true;
|
||||||
|
|||||||
54
test/test.js
54
test/test.js
@@ -491,19 +491,19 @@
|
|||||||
(function() {
|
(function() {
|
||||||
test('should work when the target function is overwritten', 2, function() {
|
test('should work when the target function is overwritten', 2, function() {
|
||||||
var object = {
|
var object = {
|
||||||
'name': 'moe',
|
'name': 'fred',
|
||||||
'greet': function(greeting) {
|
'greet': function(greeting) {
|
||||||
return greeting + ': ' + this.name;
|
return greeting + ' ' + this.name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var func = _.bindKey(object, 'greet', 'hi');
|
var func = _.bindKey(object, 'greet', 'hi');
|
||||||
equal(func(), 'hi: moe');
|
equal(func(), 'hi fred');
|
||||||
|
|
||||||
object.greet = function(greeting) {
|
object.greet = function(greeting) {
|
||||||
return greeting + ' ' + this.name + '!';
|
return greeting + ' ' + this.name + '!';
|
||||||
};
|
};
|
||||||
equal(func(), 'hi moe!');
|
equal(func(), 'hi fred!');
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -3117,30 +3117,30 @@
|
|||||||
|
|
||||||
test('should merge `source` into the destination object', 1, function() {
|
test('should merge `source` into the destination object', 1, function() {
|
||||||
var names = {
|
var names = {
|
||||||
'stooges': [
|
'characters': [
|
||||||
{ 'name': 'moe' },
|
{ 'name': 'barney' },
|
||||||
{ 'name': 'larry' }
|
{ 'name': 'fred' }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
var ages = {
|
var ages = {
|
||||||
'stooges': [
|
'characters': [
|
||||||
{ 'age': 40 },
|
{ 'age': 36 },
|
||||||
{ 'age': 50 }
|
{ 'age': 40 }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
var heights = {
|
var heights = {
|
||||||
'stooges': [
|
'characters': [
|
||||||
{ 'height': '5\'4"' },
|
{ 'height': '5\'4"' },
|
||||||
{ 'height': '5\'5"' }
|
{ 'height': '5\'5"' }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
var expected = {
|
var expected = {
|
||||||
'stooges': [
|
'characters': [
|
||||||
{ 'name': 'moe', 'age': 40, 'height': '5\'4"' },
|
{ 'name': 'barney', 'age': 36, 'height': '5\'4"' },
|
||||||
{ 'name': 'larry', 'age': 50, 'height': '5\'5"' }
|
{ 'name': 'fred', 'age': 40, 'height': '5\'5"' }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -3552,10 +3552,10 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
test('should return an array of property values from each element of a collection', 1, function() {
|
test('should return an array of property values from each element of a collection', 1, function() {
|
||||||
var objects = [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }],
|
var objects = [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }],
|
||||||
actual = _.pluck(objects, 'name');
|
actual = _.pluck(objects, 'name');
|
||||||
|
|
||||||
deepEqual(actual, ['moe', 'larry']);
|
deepEqual(actual, ['barney', 'fred']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with an object for `collection`', 1, function() {
|
test('should work with an object for `collection`', 1, function() {
|
||||||
@@ -5215,12 +5215,12 @@
|
|||||||
[]
|
[]
|
||||||
],
|
],
|
||||||
'2-tuples': [
|
'2-tuples': [
|
||||||
[['moe', 'larry'], [30, 40]],
|
[['barney', 'fred'], [36, 40]],
|
||||||
[['moe', 30], ['larry', 40]]
|
[['barney', 36], ['fred', 40]]
|
||||||
],
|
],
|
||||||
'3-tuples': [
|
'3-tuples': [
|
||||||
[['moe', 'larry'], [30, 40], [true, false]],
|
[['barney', 'fred'], [36, 40], [true, false]],
|
||||||
[['moe', 30, true], ['larry', 40, false]]
|
[['barney', 36, true], ['fred', 40, false]]
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -5234,8 +5234,8 @@
|
|||||||
|
|
||||||
test('should work with tuples of different lengths', 4, function() {
|
test('should work with tuples of different lengths', 4, function() {
|
||||||
var pair = [
|
var pair = [
|
||||||
[['moe', 30], ['larry', 40, false]],
|
[['barney', 36], ['fred', 40, false]],
|
||||||
[['moe', 'larry'], [30, 40], [undefined, false]]
|
[['barney', 'fred'], [36, 40], [undefined, false]]
|
||||||
];
|
];
|
||||||
|
|
||||||
var actual = _.zip(pair[0]);
|
var actual = _.zip(pair[0]);
|
||||||
@@ -5244,11 +5244,11 @@
|
|||||||
|
|
||||||
actual = _.zip.apply(_, actual);
|
actual = _.zip.apply(_, actual);
|
||||||
ok(2 in actual[0]);
|
ok(2 in actual[0]);
|
||||||
deepEqual(actual, [['moe', 30, undefined], ['larry', 40, false]]);
|
deepEqual(actual, [['barney', 36, undefined], ['fred', 40, false]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should support consuming it\'s return value', 1, function() {
|
test('should support consuming it\'s return value', 1, function() {
|
||||||
var expected = [['moe', 'larry'], [30, 40]];
|
var expected = [['barney', 'fred'], [36, 40]];
|
||||||
deepEqual(_.zip(_.zip(_.zip(_.zip(expected)))), expected);
|
deepEqual(_.zip(_.zip(_.zip(_.zip(expected)))), expected);
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
@@ -5258,8 +5258,8 @@
|
|||||||
QUnit.module('lodash.zipObject');
|
QUnit.module('lodash.zipObject');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var object = { 'moe': 30, 'larry': 40 },
|
var object = { 'barney': 36, 'fred': 40 },
|
||||||
array = [['moe', 30], ['larry', 40]];
|
array = [['barney', 36], ['fred', 40]];
|
||||||
|
|
||||||
test('should skip falsey elements in a given two dimensional array', 1, function() {
|
test('should skip falsey elements in a given two dimensional array', 1, function() {
|
||||||
var actual = _.zipObject(array.concat(falsey));
|
var actual = _.zipObject(array.concat(falsey));
|
||||||
@@ -5267,7 +5267,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should zip together key/value arrays into an object', 1, function() {
|
test('should zip together key/value arrays into an object', 1, function() {
|
||||||
var actual = _.zipObject(['moe', 'larry'], [30, 40]);
|
var actual = _.zipObject(['barney', 'fred'], [36, 40]);
|
||||||
deepEqual(actual, object);
|
deepEqual(actual, object);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user