xor
javascript
复制代码
xor([1, 2], [2, 3], [3, 4]) // [1, 4]
javascript
复制代码
xorBy([{ x: 1 }], [{ x: 2 }, { x: 1, y: 1 }], 'x'); // [ { x: 2 } ]
javascript
复制代码
var objects = [{ x: 1, y: 2 }, { x: 2, y: 1 }];
var others = [{ x: 1, y: 1 }, { x: 1, y: 2 }];
xorWith(objects, others, _.isEqual); // => [{ x: 2, y: 1 }, { x: 1, y: 1 }]
escape
javascript
复制代码
escape('aa, bb, &<>" cc');//aa, bb, &<>" cc
wrap
javascript
复制代码
var p = wrap(escape, function (func, text) {
return '<p>' + func(text) + '</p>';
});
p('aa, bb, & cc') // <p>fred%2C%20barney%2C%20%26%20pebbles</p>
at
javascript
复制代码
var object = { 'a': [
{ 'b': { 'c': 3 } },
4
]
};
at(object, ['a[0].b.c', 'a[1]']) // => [ 3, 4 ]
before
javascript
复制代码
const fn = before(3, () => {
console.log(11111);
})
fn() // 11111
fn() // 11111
fn() // 没有反应
fn() // 没有反应
after
javascript
复制代码
var done = after(2, ()=>{ console.log(1) });
forEach(['profile', 'settings'], function(type) {
asyncSave({ 'type': type, 'complete': done });
});
chain
javascript
复制代码
chain([
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'pebbles', 'age': 1 }
]).sortBy('age').map(function (o) {
return o.user + ' is ' + o.age;
}).head() // { 'user': 'pebbles', 'age': 1 }
chunk
javascript
复制代码
chunk(['a', 'b', 'c', 'd', 'e'], 2) // [ [ 'a', 'b' ], [ 'c', 'd' ], [ 'e' ] ]
clone
javascript
复制代码
var a = [{ 'a': 1 }, { 'b': 2 }];
var b = clone(a);
b[0] === a[0] // true
cloneDeep
javascript
复制代码
var a = [{ 'a': 1 }, { 'b': 2 }];
var b = cloneDeep(a);
b[0] === a[0] // false
isEmpty
javascript
复制代码
isEmpty(undefined);// => true
isEmpty(null);// => true
isEmpty(true);// => true
isEmpty(1);// => true
isEmpty("zanlan");// => true
isEmpty([]);// => true
isEmpty({});// => true
isEmpty([1, 2, 3]);// => false
isEmpty({ 'a': 1 });// => false
isEqual
javascript
复制代码
isEqual({}, {}) // true
intersection
javascript
复制代码
intersection([2, 1], [4, 2], [1, 2]); // => [2]
javascript
复制代码
intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor); // => [2.1]
intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); // => [{ 'x': 1 }]
javascript
复制代码
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 }]
uniq
javascript
复制代码
uniq([2, 1, 2]) // => [2, 1]
javascript
复制代码
uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]
javascript
复制代码
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]
uniqWith(objects, isEqual);// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
union
javascript
复制代码
union([2], [1, 2]) // => [2, 1]
javascript
复制代码
unionBy([2.1], [1.2, 2.3], Math.floor);// => [2.1, 1.2]
unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');// => [{ 'x': 1 }, { 'x': 2 }]
javascript
复制代码
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 }]
difference
javascript
复制代码
difference([1, 2, 3], [1, 3, 4, 5]); // [2]
javascript
复制代码
differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);// => [3.1, 1.3]
differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');// => [{ 'x': 2 }]
javascript
复制代码
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);// => [{ 'x': 2, 'y': 1 }]
flatten
javascript
复制代码
flatten([1, [2, [3, [4]], 5]]);// => [1, 2, [3, [4]], 5]
javascript
复制代码
flattenDeep([1, [2, [3, [4]], 5]]);// => [1, 2, 3, 4, 5]
javascript
复制代码
var array = [1, [2, [3, [4]], 5]];
flattenDepth(array, 1); // => [1, 2, [3, [4]], 5]
flattenDepth(array, 2); // => [1, 2, 3, [4], 5]