XJQ124 / Some-notes

本仓库记录一些电脑方面的小技巧,包含各个方面
0 stars 0 forks source link

学习Lodash的第二天(Day:14) #18

Open XJQ124 opened 10 months ago

XJQ124 commented 10 months ago

学习至函数部分

下面是今天的学习内容:

  //11.23
  //23、_.join(array, [separator=','])
  //分离数组
  const R =  _.join(['a', 'b', 'c'], '~');
  console.log(R);
  // => 'a~b~c'

  //24、_.last(array)
  //获取array中的最后一个元素。
  const S = _.last([1,2,3]);
  console.log(S);

  //25、_.lastIndexOf(array, value, [fromIndex=array.length-1])
  //这个方法类似_.indexOf ,区别是它是从右到左遍历array的元素。
  const T = _.lastIndexOf([1,2,4,5,6,7,7],2);
  console.log(T);

  const U = _.lastIndexOf([1,3,2,3,4,56,4,2,2,3],2,4)
  console.log(U)

  //26、_.nth(array, [n=0])
  //获取array数组的第n个元素。如果n为负数,则返回从数组结尾开始的第n个元素。

  //27、_.pull(array, [values])
  //移除数组array中所有和给定值相等的元素,使用SameValueZero 进行全等比较。

  const V = _.pull([1,2,3,5,6,7,85,43,3,3,34,2],2,1)
  console.log(V)

  //28、_.pullAll(array, values)
  //移除数组

  //29、_.pullAllBy(array, values, [iteratee=_.identity])
  //这个方法类似于_.pullAll ,区别是这个方法接受一个 iteratee(迭代函数) 调用 array 和 values的每个值以产生一个值,通过产生的值进行了比较。iteratee 会传入一个参数: (value)。

  //30、_.pullAllWith(array, values, [comparator])
  //比较数组,也是类似,相同的删除,剩下的输出

  //31、_.pullAt(array, [indexes])
  //根据索引 indexes,移除array中对应的元素,并返回被移除元素的数组。
  //就是移除索引值

  //32、_.remove(array, [predicate=_.identity])
  //_.remove 方法用于从数组中移除满足条件的元素,它会修改原始数组,并返回被移除的元素组成的新数组。

  //33、_.reverse(array)
  //反转数组

  //34、_.slice(array, [start=0], [end=array.length])
  //裁剪数组,从给定的索引位置开始,但不包括结束位置。
  const W = _.slice([1,2,3,4,5,6,7,8],2,5)
  console.log(W)

  //35、_.sortedIndex(array, value)
  //使用二进制的方式检索来决定 value值 应该插入到数组中 尽可能小的索引位置,以保证array的排序。
  const X = _.sortedIndex([30,50],40)
  console.log(X)

  //36、_.sortedIndexBy(array, value, [iteratee=_.identity])
  //这个方法类似_.sortedIndex ,除了它接受一个 iteratee (迭代函数),调用每一个数组(array)元素,返回结果和value 值比较来计算排序。iteratee 会传入一个参数:(value)。

  //37、_.sortedIndexOf(array, value)
  //这个方法类似_.indexOf,除了它是在已经排序的数组array上执行二进制检索。

  _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  // => 1

  //38、_.sortedLastIndex(array, value)
  //此方法类似于_.sortedIndex,除了 它返回 value值 在 array 中尽可能大的索引位置(index)。
  _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  // => 4

  //39、_.sortedLastIndexBy(array, value, [iteratee=_.identity])
  //这个方法类似_.sortedLastIndex ,除了它接受一个 iteratee (迭代函数),调用每一个数组(array)元素,返回结果和value 值比较来计算排序。iteratee 会传入一个参数:(value)。
  var objects = [{ 'x': 4 }, { 'x': 5 }];

  _.sortedLastIndexBy(objects, { 'x': 4 }, function (o) { return o.x; });
  // => 1

  // The `_.property` iteratee shorthand.
  _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  // => 1

  //40、_.sortedLastIndexOf(array, value)
  //这个方法类似_.lastIndexOf,除了它是在已经排序的数组array上执行二进制检索。
  _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  // => 3
  //41、_.sortedUniq(array)
  //这个方法类似_.uniq,除了它会优化排序数组。
  _.sortedUniq([1, 1, 2]);
  // => [1, 2]

  //42、_.sortedUniqBy(array, [iteratee])
  //这个方法类似_.uniqBy,除了它会优化排序数组。
  _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  // => [1.1, 2.3]

  //43、_.tail(array)
  //获取除了array数组第一个元素以外的全部元素。
  _.tail([1, 2, 3]);
  // => [2, 3]

  //44、_.take(array, [n=1])
  //创建一个数组切片,从array数组的起始元素开始提取n个元素。
  _.take([1, 2, 3]);
  // => [1]

  _.take([1, 2, 3], 2);
  // => [1, 2]

  _.take([1, 2, 3], 5);
  // => [1, 2, 3]

  _.take([1, 2, 3], 0);
  // => []

  //45、_.takeRight(array, [n=1])
  //创建一个数组切片,从array数组的最后一个元素开始提取n个元素。
  _.takeRight([1, 2, 3]);
  // => [3]

  _.takeRight([1, 2, 3], 2);
  // => [2, 3]

  _.takeRight([1, 2, 3], 5);
  // => [1, 2, 3]

  _.takeRight([1, 2, 3], 0);
  // => []

  //46、_.takeRightWhile(array, [predicate=_.identity])
  //从array数组的最后一个元素开始提取元素,直到 predicate 返回假值。predicate 会传入三个参数: (value, index, array)
  var users = [
    { 'user': 'barney', 'active': true },
    { 'user': 'fred', 'active': false },
    { 'user': 'pebbles', 'active': false }
  ];

  _.takeRightWhile(users, function (o) { return !o.active; });
  // => objects for ['fred', 'pebbles']

  // The `_.matches` iteratee shorthand.
  _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  // => objects for ['pebbles']

  // The `_.matchesProperty` iteratee shorthand.
  _.takeRightWhile(users, ['active', false]);
  // => objects for ['fred', 'pebbles']

  // The `_.property` iteratee shorthand.
  _.takeRightWhile(users, 'active');
  // => []

  //47、_.takeWhile(array, [predicate=_.identity])
  //从array数组的起始元素开始提取元素,,直到 predicate 返回假值。predicate 会传入三个参数: (value, index, array)。

  var users = [
    { 'user': 'barney', 'active': false },
    { 'user': 'fred', 'active': false },
    { 'user': 'pebbles', 'active': true }
  ];

  _.takeWhile(users, function (o) { return !o.active; });
  // => objects for ['barney', 'fred']

  // The `_.matches` iteratee shorthand.
  _.takeWhile(users, { 'user': 'barney', 'active': false });
  // => objects for ['barney']

  // The `_.matchesProperty` iteratee shorthand.
  _.takeWhile(users, ['active', false]);
  // => objects for ['barney', 'fred']

  // The `_.property` iteratee shorthand.
  _.takeWhile(users, 'active');
  // => []

  //48、_.union([arrays])
  //创建一个按顺序排列的唯一值的数组。所有给定数组的元素值使用SameValueZero做等值比较。(注: arrays(数组)的并集,按顺序返回,返回数组的元素是唯一的)
  _.union([2], [1, 2]);
  // => [2, 1]

  //49、_.unionBy([arrays], [iteratee=_.identity])
  //这个方法类似_.union ,除了它接受一个 iteratee (迭代函数),调用每一个数组(array)的每个元素以产生唯一性计算的标准。iteratee 会传入一个参数:(value)。
  _.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 }]

  //50、_.unionWith([arrays], [comparator])
  //这个方法类似_.union, 除了它接受一个 comparator 调用比较arrays数组的每一个元素。 comparator 调用时会传入2个参数: (arrVal, othVal)。

  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 }]

  //51、_.uniq(array)
  //创建一个去重后的array数组副本。使用了SameValueZero 做等值比较。只有第一次出现的元素才会被保留。
  //就是去重
  _.uniq([2, 1, 2]);
  // => [2, 1]

  //52、_.uniqBy(array, [iteratee = _.identity])
  //这个方法类似_.uniq ,除了它接受一个 iteratee (迭代函数),调用每一个数组(array)的每个元素以产生唯一性计算的标准。iteratee 调用时会传入一个参数:(value)。
  //这个就是计算每次第一次出现的东西就行

  _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  // => [2.1, 1.2]

  // The `_.property` iteratee shorthand.
  _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  // => [{ 'x': 1 }, { 'x': 2 }]

  //53、_.uniqWith(array, [comparator])
  //这个方法类似_.uniq, 除了它接受一个 comparator 调用比较arrays数组的每一个元素。 comparator 调用时会传入2个参数: (arrVal, othVal)。

  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 }]

  //54、_.unzip(array)
  //这个方法类似于_.zip,除了它接收分组元素的数组,并且创建一个数组,分组元素到打包前的结构。(:返回数组的第一个元素包含所有的输入数组的第一元素,第一个元素包含了所有的输入数组的第二元素,依此类推。)
  var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
  // => [['fred', 30, true], ['barney', 40, false]]

  _.unzip(zipped);
  // => [['fred', 'barney'], [30, 40], [true, false]]

  //55、_.unzipWith(array, [iteratee=_.identity])
  //此方法类似于_.unzip,除了它接受一个iteratee指定重组值应该如何被组合。iteratee 调用时会传入每个分组的值: (...group
  var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  // => [[1, 10, 100], [2, 20, 200]]

  _.unzipWith(zipped, _.add);
  // => [3, 30, 300]

  //56、_.without(array, [values])
  //创建一个剔除所有给定值的新数组,剔除值的时候,使用SameValueZero做相等比较。
  _.without([2, 1, 2, 3], 1, 2);
  // => [3]

  //57、_.xor([arrays])
  //创建一个给定数组唯一值的数组,使用symmetric difference做等值比较。返回值的顺序取决于他们数组的出现顺序。
  //就是返回他们的不相同的数字
  _.xor([2, 1], [2, 3]);
  // => [1, 3]

  //58、_.xorBy([arrays], [iteratee=_.identity])
  //这个方法类似_.xor ,除了它接受 iteratee(迭代器),这个迭代器 调用每一个 arrays(数组)的每一个值,以生成比较的新值。iteratee 调用一个参数:(value).

  _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  // => [1.2, 3.4]
  _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  // => [{ 'x': 2 }]

  //58、_.xorWith([arrays], [comparator])
  //该方法是像_.xor,除了它接受一个 comparator ,以调用比较数组的元素。 comparator 调用2个参数:(arrVal, othVal).
  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 }]
  //该系列函数,主要是不同的才留,相同的不要

  //59、_.zip([arrays])
  //创建一个分组元素的数组,数组的第一个元素包含所有给定数组的第一个元素,数组的第二个元素包含所有给定数组的第二个元素,以此类推
  _.zip(['fred', 'barney'], [30, 40], [true, false]);
  // => [['fred', 30, true], ['barney', 40, false]]
  //就是按顺序合并数组,具体看例子

  //60、_.zipObject([props=[]], [values=[]])
  //这个方法类似_.fromPairs,除了它接受2个数组,第一个数组中的值作为属性标识符(属性名),第二个数组中的值作为相应的属性值。
  _.zipObject(['a', 'b'], [1, 2]);
  // => { 'a': 1, 'b': 2 }
  //作为对象用

  //61、_.zipObjectDeep([props=[]], [values=[]])
  //该函数用于根据给定的路径数组和值数组创建一个嵌套的对象。
  _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }

  //62、_.zipWith([arrays], [iteratee=_.identity])
  //这个方法类似于_.zip,不同之处在于它接受一个 iteratee(迭代函数),来 指定分组的值应该如何被组合。 该iteratee调用每个组的元素: (...group).

  _.zipWith([1, 2], [10, 20], [100, 200], function (a, b, c) {
    return a + b + c;
  });
  // => [111, 222]

  //集合部分
  //1、_.countBy(collection, [iteratee=_.identity])
  //创建一个组成对象,key(键)是经过 iteratee(迭代函数) 执行处理collection中每个元素后返回的结果,每个key(键)对应的值是 iteratee(迭代函数)返回该key(键)的次数(注:迭代次数)。 iteratee 调用一个参数:(value)。
  _.countBy([6.1, 4.2, 6.3], Math.floor);
  // => { '4': 1, '6': 2 }

  // The `_.property` iteratee shorthand.
  _.countBy(['one', 'two', 'three'], 'length');
  // => { '3': 2, '5': 1 }

  //2、_.forEach(collection, [iteratee=_.identity])
  //调用 iteratee 遍历 collection(集合) 中的每个元素, iteratee 调用3个参数: (value, index|key, collection)。 如果迭代函数(iteratee)显式的返回 false ,迭代会提前退出。

  _([1, 2]).forEach(function (value) {
    console.log(value);
  });
  // => Logs `1` then `2`.

  _.forEach({ 'a': 1, 'b': 2 }, function (value, key) {
    console.log(key);
  });
  // => Logs 'a' then 'b' (iteration order is not guaranteed).

  //3、_.forEachRight(collection, [iteratee=_.identity])
  //与上面类似,不过是从右到左

  //4、_.every(collection, [predicate=_.identity])
  //通过 predicate(断言函数) 检查 collection(集合)中的 所有 元素是否都返回真值。一旦 predicate(断言函数) 返回假值,迭代就马上停止。predicate(断言函数)调用三个参数: (value, index | key, collection)。
  var users = [
    { 'user': 'barney', 'age': 36, 'active': true },
    { 'user': 'fred', 'age': 40, 'active': false }
  ];

  _.filter(users, function (o) { return !o.active; });
  // => objects for ['fred']

  // The `_.matches` iteratee shorthand.
  _.filter(users, { 'age': 36, 'active': true });
  // => objects for ['barney']

  // The `_.matchesProperty` iteratee shorthand.
  _.filter(users, ['active', false]);
  // => objects for ['fred']

  // The `_.property` iteratee shorthand.
  _.filter(users, 'active');
  // => objects for ['barney']

  //5、_.find(collection, [predicate=_.identity], [fromIndex=0])
  //遍历 collection(集合)元素,返回 predicate(断言函数)第一个返回真值的第一个元素。predicate(断言函数)调用3个参数: (value, index|key, collection)。
  var users = [
    { 'user': 'barney', 'age': 36, 'active': true },
    { 'user': 'fred', 'age': 40, 'active': false },
    { 'user': 'pebbles', 'age': 1, 'active': true }
  ];

  _.find(users, function (o) { return o.age < 40; });
  // => object for 'barney'

  // The `_.matches` iteratee shorthand.
  _.find(users, { 'age': 1, 'active': true });
  // => object for 'pebbles'

  // The `_.matchesProperty` iteratee shorthand.
  _.find(users, ['active', false]);
  // => object for 'fred'

  // The `_.property` iteratee shorthand.
  _.find(users, 'active');
  // => object for 'barney'

  //6、_.findLast(collection, [predicate=_.identity], [fromIndex=collection.length-1])
  //这个方法类似_.find ,不同之处在于,_.findLast是从右至左遍历collection (集合)元素的。
  _.findLast([1, 2, 3, 4], function (n) {
    return n % 2 == 1;
  });
  // => 3

  //7、_.flatMap(collection, [iteratee=_.identity])
  //创建一个扁平化(注:同阶数组)的数组,这个数组的值来自collection(集合)中的每一个值经过 iteratee(迭代函数) 处理后返回的结果,并且扁平化合并。 iteratee 调用三个参数: (value, index|key, collection)。
  function duplicate(n) {
    return [n, n];
  }

  _.flatMap([1, 2], duplicate);
  // => [1, 1, 2, 2]

  //8、_.flatMapDeep(collection, [iteratee=_.identity])
  //这个方法类似_.flatMap 不同之处在于,_.flatMapDeep 会继续扁平化递归映射的结果。
  function duplicate(n) {
    return [[[n, n]]];
  }

  _.flatMapDeep([1, 2], duplicate);
  // => [1, 1, 2, 2]

  //9、_.flatMapDepth(collection, [iteratee=_.identity], [depth=1])
  //该方法类似_.flatMap,不同之处在于,_.flatMapDepth 会根据指定的 depth(递归深度)继续扁平化递归映射结果。

  function duplicate(n) {
    return [[[n, n]]];
  }

  _.flatMapDepth([1, 2], duplicate, 2);
  // => [[1, 1], [2, 2]]

  //10、_.forEach(collection, [iteratee=_.identity])
  //调用 iteratee 遍历 collection(集合) 中的每个元素, iteratee 调用3个参数: (value, index|key, collection)。 如果迭代函数(iteratee)显式的返回 false ,迭代会提前退出。

  _([1, 2]).forEach(function (value) {
    console.log(value);
  });
  // => Logs `1` then `2`.

  _.forEach({ 'a': 1, 'b': 2 }, function (value, key) {
    console.log(key);
  });
  // => Logs 'a' then 'b' (iteration order is not guaranteed).

  //11、_.forEachRight(collection, [iteratee=_.identity])
  //与上面相反,从右往左

  //12、_.groupBy(collection, [iteratee=_.identity])
  //创建一个对象,key 是 iteratee 遍历 collection(集合) 中的每个元素返回的结果。 分组值的顺序是由他们出现在 collection(集合) 中的顺序确定的。每个键对应的值负责生成 key 的元素组成的数组。iteratee 调用 1 个参数: (value)。
  _.groupBy([6.1, 4.2, 6.3], Math.floor);
  // => { '4': [4.2], '6': [6.1, 6.3] }

  // The `_.property` iteratee shorthand.
  _.groupBy(['one', 'two', 'three'], 'length');
  // => { '3': ['one', 'two'], '5': ['three'] }

  //13、_.includes(collection, value, [fromIndex=0])
  //检查 value(值) 是否在 collection(集合) 中。如果 collection(集合)是一个字符串,那么检查 value(值,子字符串) 是否在字符串中, 否则使用SameValueZero 做等值比较。 如果指定 fromIndex 是负数,那么从 collection(集合) 的结尾开始检索。

  _.includes([1, 2, 3], 1);
  // => true

  _.includes([1, 2, 3], 1, 2);
  // => false

  _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  // => true

  _.includes('pebbles', 'eb');
  // => true

  //14、_.includes(collection, value, [fromIndex=0])
  //检查字符串是否在集合种,输出true或者false
  _.includes([1, 2, 3], 1);
  // => true

  _.includes([1, 2, 3], 1, 2);
  // => false

  _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  // => true

  _.includes('pebbles', 'eb');
  // => true

  //15、_.invokeMap(collection, path, [args])
  //按照要求排列集合
  _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  // => [[1, 5, 7], [1, 2, 3]]

  _.invokeMap([123, 456], String.prototype.split, '');
  // => [['1', '2', '3'], ['4', '5', '6']]

  //16、_.keyBy(collection, [iteratee=_.identity])
  //创建一个对象组成, key(键) 是 collection(集合)中的每个元素经过 iteratee(迭代函数) 处理后返回的结果。 每个 key(键)对应的值是生成key(键)的最后一个元素。iteratee(迭代函数)调用1个参数:(value)。

  var array = [
    { 'dir': 'left', 'code': 97 },
    { 'dir': 'right', 'code': 100 }
  ];

  _.keyBy(array, function (o) {
    return String.fromCharCode(o.code);
  });
  // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }

  _.keyBy(array, 'dir');
  // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }

  //17、_.map(collection, [iteratee=_.identity])
  //创建一个数组,值是迭代函数遍历集合中每个元素后返回的结果,
  function square(n) {
    return n * n;
  }

  _.map([4, 8], square);
  // => [16, 64]

  _.map({ 'a': 4, 'b': 8 }, square);
  // => [16, 64] (iteration order is not guaranteed)

  var users = [
    { 'user': 'barney' },
    { 'user': 'fred' }
  ];

  // The `_.property` iteratee shorthand.
  _.map(users, 'user');
  // => ['barney', 'fred']

  //18、_.orderBy(collection, [iteratees=[_.identity]], [orders])
  //按特定要求排序
  var users = [
  { 'user': 'fred', 'age': 48 },
  { 'user': 'barney', 'age': 34 },
  { 'user': 'fred', 'age': 40 },
  { 'user': 'barney', 'age': 36 }
];

  // 以 `user` 升序排序 再  `age` 以降序排序。
  _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

  //19、_.partition(collection, [predicate=_.identity])
  //创建一个分成两组的元素数组,第一组包含predicate(断言函数)返回为 truthy(真值)的元素,第二组包含predicate(断言函数)返回为 falsey(假值)的元素。predicate 调用1个参数:(value)。
  var users = [
    { 'user': 'barney', 'age': 36, 'active': false },
    { 'user': 'fred', 'age': 40, 'active': true },
    { 'user': 'pebbles', 'age': 1, 'active': false }
  ];

  _.partition(users, function (o) { return o.active; });
  // => objects for [['fred'], ['barney', 'pebbles']]

  // The `_.matches` iteratee shorthand.
  _.partition(users, { 'age': 1, 'active': false });
  // => objects for [['pebbles'], ['barney', 'fred']]

  // The `_.matchesProperty` iteratee shorthand.
  _.partition(users, ['active', false]);
  // => objects for [['barney', 'pebbles'], ['fred']]

  // The `_.property` iteratee shorthand.
  _.partition(users, 'active');
  // => objects for [['fred'], ['barney', 'pebbles']]

  //20、_.reduce(collection, [iteratee=_.identity], [accumulator])
  //该函数用于将数组或对象的元素按照指定的迭代函数进行累积计算。
  _.reduce([1, 2], function (sum, n) {
    return sum + n;
  }, 0);
  // => 3

  _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function (result, value, key) {
    (result[value] || (result[value] = [])).push(key);
    return result;
  }, {});
  // => { '1': ['a', 'c'], '2': ['b'] } (无法保证遍历的顺序)

  //21、_.reduceRight(collection, [iteratee=_.identity], [accumulator])
  //和上面一样,不过是从右到左计算

  //22、_.reject(collection, [predicate=_.identity])
  //_.filter的反向方法;此方法 返回 predicate(断言函数) 不 返回 truthy(真值)的collection(集合)元素(注释:非真)。
  var users = [
    { 'user': 'barney', 'age': 36, 'active': false },
    { 'user': 'fred', 'age': 40, 'active': true }
  ];

  _.reject(users, function (o) { return !o.active; });
  // => objects for ['fred']

  // `_.matches` 迭代简写
  _.reject(users, { 'age': 40, 'active': true });
  // => objects for ['barney']

  // `_.matchesProperty` 迭代简写
  _.reject(users, ['active', false]);
  // => objects for ['fred']

  // `_.property` 迭代简写
  _.reject(users, 'active');
  // => objects for ['barney']

  //23、_.sample(collection)
  //从collection(集合)中获得一个随机元素。
  _.sample([1, 2, 3, 4]);
  // => 2(就是随机数)

  //24、_.sampleSize(collection, [n=1])
  //从collection(集合)中获得 n 个随机元素。
  _.sampleSize([1, 2, 3], 2);
  // => [3, 1]

  _.sampleSize([1, 2, 3], 4);
  // => [2, 3, 1]

  //25、_.shuffle(collection)
  //创建一个被打乱值的集合。 
  _.shuffle([1, 2, 3, 4]);
  // => [4, 1, 3, 2]

  //26、_.size(collection)
  //返回collection(集合)的长度,如果集合是类数组或字符串,返回其 length ;如果集合是对象,返回其可枚举属性的个数。
  //这个需要记忆一下,还是有点区别
  _.size([1, 2, 3]);
  // => 3

  _.size({ 'a': 1, 'b': 2 });
  // => 2

  _.size('pebbles');
  // => 7

  //27、_.some(collection, [predicate = _.identity])
  //通过 predicate(断言函数) 检查collection(集合)中的元素是否存在 任意 truthy(真值)的元素,一旦 predicate(断言函数) 返回 truthy(真值),遍历就停止。 predicate 调用3个参数:(value, index|key, collection)。

  _.some([null, 0, 'yes', false], Boolean);
  // => true

  var users = [
    { 'user': 'barney', 'active': true },
    { 'user': 'fred', 'active': false }
  ];

  // The `_.matches` iteratee shorthand.
  _.some(users, { 'user': 'barney', 'active': false });
  // => false

  // The `_.matchesProperty` iteratee shorthand.
  _.some(users, ['active', false]);
  // => true

  // The `_.property` iteratee shorthand.
  _.some(users, 'active');
  // => true

  //28、_.sortBy(collection, [iteratees=[_.identity]])
  //创建一个元素数组。 以 iteratee 处理的结果升序排序。
  var users = [
  { 'user': 'fred', 'age': 48 },
  { 'user': 'barney', 'age': 36 },
  { 'user': 'fred', 'age': 40 },
  { 'user': 'barney', 'age': 34 }
];

  _.sortBy(users, function (o) { return o.user; });
  // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

  _.sortBy(users, ['user', 'age']);
  // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]

  _.sortBy(users, 'user', function (o) {
    return Math.floor(o.age / 10);
  });
  // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

  //函数部分
  //1、_.after(n, func)
  //_.before的反向函数; 此方法创建一个函数,当他被调用n或更多次之后将马上触发func 。还是比较清楚的哈
  var saves = ['profile', 'settings'];

  var done = _.after(saves.length, function () {
    console.log('done saving!');
  });

  _.forEach(saves, function (type) {
    asyncSave({ 'type': type, 'complete': done });
  });
  // => Logs 'done saving!' after the two async saves have completed.

  //2、_.ary(func, [n=func.length])
  //创建一个调用func的函数。调用func时最多接受 n个参数,忽略多出的参数。

  _.map(['6', '8', '10'], _.ary(parseInt, 1));
  // => [6, 8, 10]

  //3、_.before(n, func)
  //创建一个函数,不能调用超过n次,值取最后一次的值
  jQuery(element).on('click', _.before(5, addContactToList));
  // => allows adding up to 4 contacts to the list

  //4、_.bind(func, thisArg, [partials])
  //创建一个调用func的函数,thisArg绑定func函数中的 this (注:this的上下文为thisArg) ,并且func函数会接收partials附加参数。
  var greet = function (greeting, punctuation) {
    return greeting + ' ' + this.user + punctuation;
  };

  var object = { 'user': 'fred' };

  var bound = _.bind(greet, object, 'hi');
  bound('!');
  // => 'hi fred!'

  // Bound with placeholders.
  var bound = _.bind(greet, object, _, '!');
  bound('hi');
  // => 'hi fred!'

  //5、_.bindKey(object, key, [partials])
  //创建一个函数,在object[key]上通过接收partials附加参数,调用这个方法。

  var object = {
    'user': 'fred',
    'greet': function (greeting, punctuation) {
      return greeting + ' ' + this.user + punctuation;
    }
  };

  var bound = _.bindKey(object, 'greet', 'hi');
  bound('!');
  // => 'hi fred!'

  object.greet = function (greeting, punctuation) {
    return greeting + 'ya ' + this.user + punctuation;
  };

  bound('!');
  // => 'hiya fred!'

  // Bound with placeholders.
  var bound = _.bindKey(object, 'greet', _, '!');
  bound('hi');
  // => 'hiya fred!'

  //6、_.curry(func, [arity=func.length])
  //创建一个函数,该函数接收 func 的参数,要么调用func返回的结果,如果 func 所需参数已经提供,则直接返回 func 所执行的结果。或返回一个函数,接受余下的func 参数的函数,可以使用 func.length 强制需要累积的参数个数。

  var abc = function (a, b, c) {
    return [a, b, c];
  };

  var curried = _.curry(abc);

  curried(1)(2)(3);
  // => [1, 2, 3]

  curried(1, 2)(3);
  // => [1, 2, 3]

  curried(1, 2, 3);
  // => [1, 2, 3]

  // Curried with placeholders.
  curried(1)(_, 3)(2);
  // => [1, 2, 3]

  //7、_.curryRight(func, [arity=func.length])
  //这个方法类似_.curry。 除了它接受参数的方式用_.partialRight 代替了_.partial。_.curryRight.placeholder值,默认是以 _ 作为附加部分参数的占位符。

  var abc = function (a, b, c) {
    return [a, b, c];
  };

  var curried = _.curryRight(abc);

  curried(3)(2)(1);
  // => [1, 2, 3]

  curried(2, 3)(1);
  // => [1, 2, 3]

  curried(1, 2, 3);
  // => [1, 2, 3]

  // Curried with placeholders.
  curried(3)(1, _)(2);
  // => [1, 2, 3]

  //8、_.debounce(func, [wait=0], [options=])
  //创建一个 debounced(防抖动)函数,该函数会从上一次被调用后,延迟 wait 毫秒后调用 func 方法。
  // 避免窗口在变动时出现昂贵的计算开销。
  jQuery(window).on('resize', _.debounce(calculateLayout, 150));

  // 当点击时 `sendMail` 随后就被调用。
  jQuery(element).on('click', _.debounce(sendMail, 300, {
    'leading': true,
    'trailing': false
  }));

  // 确保 `batchLog` 调用1次之后,1秒内会被触发。
  var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  var source = new EventSource('/stream');
  jQuery(source).on('message', debounced);

  // 取消一个 trailing 的防抖动调用
  jQuery(window).on('popstate', debounced.cancel);

  //9、_.defer(func, [args])
  //推迟调用func,直到当前堆栈清理完毕。 调用时,任何附加的参数会传给func。

  _.defer(function (text) {
    console.log(text);
  }, 'deferred');
  // => 一毫秒或更久一些输出 'deferred'。

  //10、_.delay(func, wait, [args])
  //延迟 wait 毫秒后调用 func。 调用时,任何附加的参数会传给func。
  _.delay(function (text) {
    console.log(text);
  }, 1000, 'later');
  // => 一秒后输出 'later'。

  //11、_.flip(func)
  //创建一个函数,调用func时候接收翻转的参数。
  var flipped = _.flip(function () {
    return _.toArray(arguments);
  });

  flipped('a', 'b', 'c', 'd');
  // => ['d', 'c', 'b', 'a']

  //12、_.memoize(func, [resolver])
  //创建一个会缓存 func 结果的函数。 如果提供了 resolver ,就用 resolver 的返回值作为 key 缓存函数的结果。 默认情况下用第一个参数作为缓存的 key。 func 在调用时 this 会绑定在缓存函数上。
  var object = { 'a': 1, 'b': 2 };
  var other = { 'c': 3, 'd': 4 };

  var values = _.memoize(_.values);
  values(object);
  // => [1, 2]

  values(other);
  // => [3, 4]

  object.a = 2;
  values(object);
  // => [1, 2]

  // 修改结果缓存。
  values.cache.set(object, ['a', 'b']);
  values(object);
  // => ['a', 'b']

  // 替换 `_.memoize.Cache`。
  _.memoize.Cache = WeakMap;

  //13、_.negate(predicate)
  //创建一个针对断言函数 func 结果取反的函数。 func 断言函数被调用的时候,this 绑定到创建的函数,并传入对应参数。
  function isEven(n) {
    return n % 2 == 0;
  }

  _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  // => [1, 3, 5]

  //14、_.once(func)
  //创建一个只能调用 func 一次的函数。 重复调用返回第一次调用的结果。 func 调用时, this 绑定到创建的函数,并传入对应参数。
  var initialize = _.once(createApplication);
  initialize();
  initialize();
  // `initialize` 只能调用 `createApplication` 一次。

  //15、_.overArgs(func, [transforms=[_.identity]])
  //创建一个函数,调用func时参数为相对应的transforms的返回值。

  function doubled(n) {
    return n * 2;
  }

  function square(n) {
    return n * n;
  }

  var func = _.overArgs(function (x, y) {
    return [x, y];
  }, [square, doubled]);

  func(9, 3);
  // => [81, 6]

  func(10, 5);
  // => [100, 10]

//16、_.partial(func, [partials])
  var greet = function (greeting, name) {
    return greeting + ' ' + name;
  };
  var sayHelloTo = _.partial(greet, 'hello');
  sayHelloTo('fred');
  // => 'hello fred'

我是直接把例子和作用全都写到了代码里,看起来比较粗暴,那种一眼就可以看出来作用的方法,我就没有写例子,只标记了名字,明天争取把这部分解决掉