Skip to content

Instantly share code, notes, and snippets.

View thinnakrit's full-sized avatar
🏕️
I love camping :D

Thinnakrit thinnakrit

🏕️
I love camping :D
View GitHub Profile
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(_.slice(animals,2));
// expected output: Array ["camel", "duck", "elephant"]
console.log(_.slice(animals,2, 4));
// expected output: Array ["camel", "duck"]
console.log(_.slice(animals,1, 5));
// expected output: Array ["bison", "camel", "duck", "elephant"]
// intersection
_.intersection([2, 1], [2, 3]);
// => [2]
// intersectionBy
_.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [2.1]
// dropWhile
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': true }
];
_.dropWhile(users, function(o) { return !o.active; });
// => objects for ['pebbles']
_.dropRight([1, 2, 3]);
// => [1, 2]
_.dropRight([1, 2, 3], 2);
// => [1]
_.dropRight([1, 2, 3], 5);
// => []
_.dropRight([1, 2, 3], 0);
_.drop([1, 2, 3]);
// => [2, 3]
_.drop([1, 2, 3], 2);
// => [3]
_.drop([1, 2, 3], 5);
// => []
_.drop([1, 2, 3], 0);
_.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 }]
_.difference([2, 1], [2, 3]);
// => [1]
var array = [1];
var other = _.concat(array, 2, [3], [[4]]);
console.log(other);
// => [1, 2, 3, [4]]
console.log(array);
// => [1]
_.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]
_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
 
_.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]