- isArrayLike
- isArrayLikeObject
- isBoolean
- isNumber
- isFunction
- isString
- isDate
- isEmpty
- isEqual
- isEqualWith
- isFunction
- toArray
- gte
- lte
- clone
- cloneDeep
- chunk
- difference
- differenceBy
- differenceWith
- pullAll
- pullAllBy
- union
- unionBy
- unionWith
- interstionBy
- intersectionWith
- countBy
- orderBy
- filter
- map
- sample
- sampleBy
- shuffle
- defaults
- forIn
- forOwn
- ary
- map
- unary
- curry
- curryRight
- partial
- memorize
- https://lodash.com/)
- http://devdocs.io/lodash~4/
- file:///C:/Users/Creativos6_/Downloads/lodashcookbook-sample.pdf
_.noop
, This method returns undefined.
_.times(2, _.noop); // => [undefined, undefined]
_.nthArg([n=0])
, Creates a function that gets the argument at indexn
. Ifn
is negative, the nth argument from the end is returned.
var func = _.nthArg(1);
func('a', 'b', 'c', 'd'); // => 'b'
var func = _.nthArg(-2);
func('a', 'b', 'c', 'd'); // => 'c'
_.isArrayLike(value)
, A value is considered array-like if it's not a function and has avalue.length
that's an integer greater than or equal to 0 and less than or equal toNumber.MAX_SAFE_INTEGER
.
_.isArrayLike([1, 2, 3]); // => true
_.isArrayLike(document.body.children); // => true
_.isArrayLike('abc'); // => true
_.isArrayLike(_.noop); // => false
_.isArrayLikeObject(value)
, This method is like_.isArrayLike
except that it also checks ifvalue
is an object.
_.isArrayLikeObject([1, 2, 3]); // => true
_.isArrayLikeObject(document.body.children); // => true
_.isArrayLikeObject('abc'); // => false
_.isArrayLikeObject(_.noop); // => false
_.isBoolean(value)
, Checks ifvalue
is classified as a boolean primitive or object.
_.isBoolean(false); // => true
_.isBoolean(null); // => false
_.isNumber(value)
, Checks ifvalue
is classified as aNumber
primitive or object.
_.isNumber(3); // => true
_.isNumber(Number.MIN_VALUE); // => true
_.isNumber(Infinity); // => true
_.isNumber('3'); // => false
_.isString(value)
, Checks ifvalue
is classified as a String primitive or object.
_.isString('abc'); // => true
_.isString(1); // => false
_.isDate(value)
, Checks ifvalue
is classified as a Date object.
_.isDate(new Date); // => true
_.isDate('Mon April 23 2012'); // => false
_.isEmpty(value)
, Checks ifvalue
is an empty object, collection, map, or set.
_.isEmpty(null); // => true
_.isEmpty(true); // => true
_.isEmpty(1); // => true
_.isEmpty([1, 2, 3]); // => false
_.isEmpty({ 'a': 1 }); // => false
_.isEqual(value, other)
, Performs a deep comparison between two values to determine if they are equivalent.
Note: This method supports comparing arrays, array buffers, booleans, date objects, error objects, maps, numbers, Object objects, regexes, sets, strings, symbols, and typed arrays. Object objects are compared by their own, not inherited, enumerable properties. Functions and DOM nodes are compared by strict equality, i.e. ===.
var object = { 'a': 1 };
var other = { 'a': 1 };
_.isEqual(object, other); // => true
object === other; // => false
_.isEqualWith(value, other, [customizer])
, This method is like_.isEqual
except that it acceptscustomizer
which is invoked to compare values. Ifcustomizer
returnsundefined
, comparisons are handled by the method instead. Thecustomizer
is invoked with up to six arguments: (objValue, othValue [, index|key, object, other, stack]).
function isGreeting(value) {
return /^h(?:i|ello)$/.test(value);
}
function customizer(objValue, othValue) {
if (isGreeting(objValue) && isGreeting(othValue)) {
return true;
}
}
var array = ['hello', 'goodbye'];
var other = ['hi', 'goodbye'];
_.isEqualWith(array, other, customizer); // => true
_.isFunction(value)
, Checks ifvalue
is classified as aFunction
object.
_.isFunction(_); // => true
_.isFunction(/abc/); // => false
_.toArray(value)
, Convertsvalue
to an array.
_.toArray({ 'a': 1, 'b': 2 }); // => [1, 2]
_.toArray('abc'); // => ['a', 'b', 'c']
_.toArray(1); // => []
_.toArray(null); // => []
_.gte(value, other)
, Checks ifvalue
is greater than or equal toother
.
_.gte(3, 1); // => true
_.gte(3, 3); // => true
_.gte(1, 3); // => false
_.lte(value, other)
, Checks ifvalue
is less than or equal toother
.
_.lte(1, 3); // => true
_.lte(3, 3); // => true
_.lte(3, 1); // => false
_.clone(value)
, Creates a shallow clone ofvalue
.
Note: This method is loosely based on the structured clone algorithm and supports cloning arrays, array buffers, booleans, date objects, maps, numbers, Object
objects, regexes, sets, strings, symbols, and typed arrays. The own enumerable properties of arguments
objects are cloned as plain objects. An empty object is returned for uncloneable values such as error objects, functions, DOM nodes, and WeakMaps.
var objects = [{ 'a': 1 }, { 'b': 2 }];
var shallow = _.clone(objects);
console.log(shallow[0] === objects[0]); // => true
_.cloneDeep(value)
, This method is like_.clone
except that it recursively clonesvalue
.
var objects = [{ 'a': 1 }, { 'b': 2 }];
var deep = _.cloneDeep(objects);
console.log(deep[0] === objects[0]); // => false
_.camelCase([string=''])
, Convertsstring
to camel case.
_.camelCase('Foo Bar'); // => 'fooBar'
_.camelCase('--foo-bar--'); // => 'fooBar'
_.camelCase('__FOO_BAR__'); // => 'fooBar'
_.capitalize([string=''])
, Converts the first character ofstring
to upper case and the remaining to lower case.
_.capitalize('FRED'); // => 'Fred'
_.deburr([string=''])
, Deburrsstring
by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.
_.deburr('déjà vu'); // => 'deja vu'
_.kebabCase([string=''])
, Convertsstring
to kebab case.
_.kebabCase('Foo Bar'); // => 'foo-bar'
_.kebabCase('fooBar'); // => 'foo-bar'
_.kebabCase('__FOO_BAR__'); // => 'foo-bar'
_.pad([string=''], [length=0], [chars=' '])
, Padsstring
on the left and right sides if it's shorter thanlength
. Padding characters are truncated if they can't be evenly divided bylength
.
[string='']
(string): The string to pad.[length=0]
(number): The padding length.[chars=' ']
(string): The string used as padding.
_.pad('abc', 8); // => ' abc '
_.pad('abc', 8, '_-'); // => '_-abc_-_'
_.pad('abc', 3); // => 'abc'
_.words([string=''], [pattern])
, Splitsstring
into an array of its words.
[string='']
(string): The string to inspect.[pattern]
(RegExp|string): The pattern to match words.
_.words('fred, barney, & pebbles'); // => ['fred', 'barney', 'pebbles']
_.words('fred, barney, & pebbles', /[^, ]+/g); // => ['fred', 'barney', '&', 'pebbles']
_.chunk(array, [size=1])
, Creates an array of elements split into groups the length ofsize
. Ifarray
can't be split evenly, the final chunk will be the remaining elements.
array
(Array): The array to process.[size=1]
(number): The length of each chunk
_.chunk(['a', 'b', 'c', 'd'], 2); // => [['a', 'b'], ['c', 'd']]
_.chunk(['a', 'b', 'c', 'd'], 3); // => [['a', 'b', 'c'], ['d']]
_.difference(array, [values])
, Creates an array ofarray
values not included in the other given arrays using SameValueZero for equality comparisons. The order and references of result values are determined by the first array.
_.difference([2, 1], [2, 3]); // => [1]
_.pull(array, [values])
, Removes all given values fromarray
using SameValueZero for equality comparisons.
Note: Unlike _.without
, this method mutates array. Use _.remove
to remove elements from an array by predicate.
var array = ['a', 'b', 'c', 'a', 'b', 'c'];
_.pull(array, 'a', 'c');
console.log(array); // => ['b', 'b']
_.pullAll(array, values)
, This method is like_.pull
except that it accepts an array of values to remove.
var array = ['a', 'b', 'c', 'a', 'b', 'c'];
_.pullAll(array, ['a', 'c']);
console.log(array); // => ['b', 'b']
_.differenceBy(array, [values], [iteratee=_.identity])
, This method is like_.difference
except that it accepts iteratee which is invoked for each element ofarray
andvalues
to generate the criterion by which they're compared. The order and references of result values are determined by the first array. The iteratee is invoked with one argument:(value).
array
(Array): The array to inspect.[values]
(...Array): The values to exclude.[iteratee=_.identity]
(Function): The iteratee invoked per element.
_.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // => [1.2]
// The `_.property` iteratee shorthand.
_.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); // => [{ 'x': 2 }]
_.differenceBy([-1,-2,-3,-4,-5],[1,3,4], Math.abs) // =>[-2,-5]
const animalCollection1 = [
{ type: 'dog', name: 'Mishka' },
{ type: 'hamster', name: 'Jasper' },
{ type: 'cat', name: 'Kota' },
];
const animalCollection2 = [
{ type: 'dog', name: 'Toby' },
{ type: 'cat', name: 'Luna' },
{ type: 'fish', name: 'Bob' },
];
_.differenceBy(
animalCollection1,
animalCollection2,
(animal) => animal.type); // => 0: {type: "hamster", name: "Jasper"}
const animalCollection1 = [
{ type: 'dog', name: 'Mishka' },
{ type: 'hamster', name: 'Jasper' },
{ type: 'cat', name: 'Kota' },
];
const animalCollection2 = [
{ type: 'dog', name: 'Toby' },
{ type: 'cat', name: 'Luna' },
{ type: 'fish', name: 'Bob' },
];
const func = (animal)=>{
return animal.type;
};
_.differenceBy(animalCollection1, animalCollection2, func); // => 0: {type: "hamster", name: "Jasper"}
_.pullAllBy(array, values, [iteratee=_.identity])
, This method is like_.pullAll
except that it acceptsiteratee
which is invoked for each element ofarray
andvalues
to generate the criterion by which they're compared. The iteratee is invoked with one argument: (value).
array
(Array): The array to modify.values
(Array): The values to remove.[iteratee=_.identity]
(Function): The iteratee invoked per element.
var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
_.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
console.log(array); // => [{ 'x': 2 }]
const animalCollection1 = [
{ type: 'dog', name: 'Mishka' },
{ type: 'hamster', name: 'Jasper' },
{ type: 'cat', name: 'Kota' },
];
const animalCollection2 = [
{ type: 'dog', name: 'Toby' },
{ type: 'cat', name: 'Luna' },
{ type: 'fish', name: 'Bob' },
];
_.pullAllBy(
animalCollection1,
animalCollection2,
(animal) => animal.type);
console.log(animalCollection1); // => 0: {type: "hamster", name: "Jasper"}
const animalCollection1 = [
{ type: 'dog', name: 'Mishka' },
{ type: 'hamster', name: 'Jasper' },
{ type: 'cat', name: 'Kota' },
];
const animalCollection2 = [
{ type: 'dog', name: 'Toby' },
{ type: 'cat', name: 'Luna' },
{ type: 'fish', name: 'Bob' },
];
const func = (animal)=>{
return animal.type;
};
_.pullAllBy(animalCollection1, animalCollection2, func);
console.log(animalCollection1); // => 0: {type: "hamster", name: "Jasper"}
_.differenceWith(array, [values], [comparator])
, This method is like_.difference
except that it acceptscomparator
which is invoked to compare elements ofarray
tovalues
. The order and references of result values are determined by the first array. The comparator is invoked with two arguments: (arrVal, othVal).
array
(Array): The array to inspect.[values]
(...Array): The values to exclude.[comparator
(Function): The comparator invoked per element.
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
_.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); // => [{ 'x': 2, 'y': 1 }]
const animalCollection1 = [
{ type: 'dog', name: 'Mishka' },
{ type: 'hamster', name: 'Jasper' },
{ type: 'cat', name: 'Kota' },
];
const animalCollection2 = [
{ type: 'dog', name: 'Toby' },
{ type: 'cat', name: 'Luna' },
{ type: 'fish', name: 'Bob' },
];
const funcwith = (animalCollection1, animalCollection2)=>{
return animalCollection1.type === animalCollection2.type;
};
_.differenceWith(animalCollection1, animalCollection2, funcwith); // => {type: "hamster", name: "Jasper"}
_.pullAllWith(array, values, [comparator])
, This method is like_.pullAll
except that it acceptscomparator
which is invoked to compare elements ofarray
tovalues
. The comparator is invoked with two arguments: (arrVal, othVal).
array
(Array): The array to modify.values
(Array): The values to remove.[comparator]
(Function): The comparator invoked per element.
var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
_.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
console.log(array); // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
const animalCollection1 = [
{ type: 'dog', name: 'Mishka' },
{ type: 'hamster', name: 'Jasper' },
{ type: 'cat', name: 'Kota' },
];
const animalCollection2 = [
{ type: 'dog', name: 'Toby' },
{ type: 'cat', name: 'Luna' },
{ type: 'fish', name: 'Bob' },
];
const funcwith = (animalCollection1, animalCollection2)=>{
return animalCollection1.type === animalCollection2.type;
};
_.pullAllWith(animalCollection1, animalCollection2, funcwith);
console.log(animalCollection1); // => {type: "hamster", name: "Jasper"}
_.union([arrays])
, Creates an array of unique values, in order, from all given arrays usingSameValueZero
for equality comparisons.
_.union([2], [1, 2]); // => [2, 1]
const coordinatesCollection1 = [
{ x: 0, y: 3 },
{ x: 2, y: 5 },
{ x: 2, y: 4 },
];
const coordinatesCollection2 = [
{ x: 0, y: 7 },
{ x: 1, y: 8 },
{ x: 2, y: 10 },
];
_.union(coordinatesCollection1, coordinatesCollection2, 'x');
// => [{x: 0, y: 3}, {x: 2, y: 5}, {x: 1, y: 8}, { x: 0, y: 7 }, { x: 1, y: 8 }, { x: 2, y: 10 } ]
_.unionBy([arrays], [iteratee=_.identity])
, This method is like_.union
except that it accepts iteratee which is invoked for each element of eacharrays
to generate the criterion by which uniqueness is computed. Result values are chosen from the first array in which the value occurs. The iteratee is invoked with one argument: (value).
[arrays]
(...Array): The arrays to inspect.[iteratee=_.identity]
(Function): The iteratee invoked per element.
_.unionBy([2.1], [1.2, 2.3], Math.floor); // => [2.1, 1.2]
// The `_.property` iteratee shorthand.
_.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); // => [{ 'x': 1 }, { 'x': 2 }]
const coordinatesCollection1 = [
{ x: 0, y: 3 },
{ x: 2, y: 5 },
{ x: 2, y: 4 },
];
const coordinatesCollection2 = [
{ x: 0, y: 7 },
{ x: 1, y: 8 },
{ x: 2, y: 10 },
{ x: 2, y: 4 },
];
_.unionBy(coordinatesCollection1, coordinatesCollection2, 'x'); // => [{x: 0, y: 3}, {x: 2, y: 5}, {x: 1, y: 8}]
_.unionWith([arrays], [comparator])
, This method is like_.union
except that it accepts comparator which is invoked to compare elements ofarrays
. Result values are chosen from the first array in which the value occurs. The comparator is invoked with two arguments: (arrVal, othVal).
[arrays]
(...Array): The arrays to inspect.[comparator]
(Function): The comparator invoked per element.
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
_.unionWith(objects, others, _.isEqual); // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
const coordinatesCollection1 = [
{ x: 0, y: 3 },
{ x: 2, y: 5 },
{ x: 2, y: 4 },
];
const coordinatesCollection2 = [
{ x: 0, y: 7 },
{ x: 1, y: 8 },
{ x: 2, y: 10 },
{ x: 2, y: 4 },
];
_.unionWith(coordinatesCollection1, coordinatesCollection2, 'x');
// => [{x: 0, y: 3}, {x: 2, y: 5}, {x: 2, y: 4}, {x: 0, y: 7}, {x: 1, y: 8}, {x: 2, y: 10}, {x: 2, y: 4}]
_.intersectionBy([arrays], [iteratee=_.identity])
, This method is like_.intersection
except that it acceptsiteratee
which is invoked for each element of eacharrays
to generate the criterion by which they're compared. The order and references of result values are determined by the first array. The iteratee is invoked with one argument: (value).
[arrays]
(...Array): The arrays to inspect.[iteratee=_.identity]
(Function): The iteratee invoked per element.
_.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // => [2.1]
// The `_.property` iteratee shorthand.
_.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); // => [{ 'x': 1 }]
const coordinatesCollection1 = [
{ x: 0, y: 3 },
{ x: 2, y: 5 },
{ x: 2, y: 4 },
];
const coordinatesCollection2 = [
{ x: 0, y: 7 },
{ x: 1, y: 8 },
{ x: 2, y: 10 },
{ x: 2, y: 4 },
];
_.intersectionBy(coordinatesCollection1, coordinatesCollection2, 'x'); // => [{x: 0, y: 3}, {x: 2, y: 5}]
_.intersectionWith([arrays], [comparator])
, This method is like_.intersection
except that it acceptscomparator
which is invoked to compare elements ofarrays
. The order and references of result values are determined by the first array. The comparator is invoked with two arguments: (arrVal, othVal).
[arrays]
(...Array): The arrays to inspect.[comparator]
(Function): The comparator invoked per element.
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
_.intersectionWith(objects, others, _.isEqual); // => [{ 'x': 1, 'y': 2 }]
const coordinatesCollection1 = [
{ x: 0, y: 7, z:2 },
{ x: 2, y: 5, z:1 },
{ x: 1, y: 1, z: 1},
];
const coordinatesCollection2 = [
{ x: 0, y: 7, z: 3 },
{ x: 1, y: 8, z: 1 },
{ x: 2, y: 10, z: 1 },
];
const func = ({x1, z1}, {x2, z2})=>{
return x1 == x2 && z1 == z2 ;
}
_.intersectionWith(coordinatesCollection1, coordinatesCollection2, func); // => {x: 0, y: 7, z: 2}