2012年4月15日
摘要: Similar towithout, but returns the values fromarraythat are not present in theotherarrays.返回数组中的差集_.difference([1, 2, 3, 4, 5], [5, 2, 10]);=> [1, 3, 4]源码:1 _.difference = function(array) {2 var rest = _.flatten(slice.call(arguments, 1), true);3 return _.filter(array, function(value){ retu... 阅读全文
posted @ 2012-04-15 23:12 himanhimao 阅读(870) 评论(0) 推荐(0) 编辑
摘要: Computes the list of values that are the intersection of all thearrays. Each value in the result is present in each of thearrays.返回数组的交集1 _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);2 => [1, 2]源码:1 _.intersection = _.intersect = function(array) {2 var rest = slice.call(arguments, 1);3 ... 阅读全文
posted @ 2012-04-15 23:09 himanhimao 阅读(417) 评论(0) 推荐(0) 编辑
摘要: Computes the union of the passed-inarrays: the list of unique items, in order, that are present in one or more of thearrays.返回数组中的并集_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);=> [1, 2, 3, 101, 10]源码:1 _.union = function() {2 return _.uniq(_.flatten(arguments, true));3 }; 阅读全文
posted @ 2012-04-15 23:07 himanhimao 阅读(317) 评论(0) 推荐(0) 编辑
摘要: Returns a copy of thearraywith all instances of thevaluesremoved.===is used for the equality test移除数组中不需要的值,值的数量可以是N_.without([1, 2, 1, 0, 3, 1, 4], 0, 1);=> [2, 3, 4]源码: _.without = function(array) { return _.difference(array, slice.call(arguments, 1)); }; 阅读全文
posted @ 2012-04-15 23:01 himanhimao 阅读(297) 评论(0) 推荐(0) 编辑
摘要: Flattens a nestedarray(the nesting can be to any depth). If you passshallow, the array will only be flattened a single level将多维嵌套数组转换成一维数组,如果shallow的值为true,数组嵌套级别只提升一级1 _.flatten([1, [2], [3, [[4]]]]);2 => [1, 2, 3, 4];3 4 _.flatten([1, [2], [3, [[4]]]], true);5 => [1, 2, 3, [[4]]]源码:1 _.flatt 阅读全文
posted @ 2012-04-15 22:54 himanhimao 阅读(525) 评论(0) 推荐(0) 编辑
摘要: Returns a copy of thearraywith all falsy values removed. In JavaScript,false,null,0,"",undefinedandNaNare all falsy.返回的数组将不再包括,false,null,0,"",undefined1 _.compact([0, 1, false, 2, '', 3]);2 => [1, 2, 3]源码: _.compact = function(array) { return _.filter(array, function( 阅读全文
posted @ 2012-04-15 22:42 himanhimao 阅读(215) 评论(0) 推荐(0) 编辑
摘要: Returns therestof the elements in an array. Pass anindexto return the values of the array from that index onward返回数组中的元素的其余部分。通过索引返回数组中的值,从该指数开始. 别名tail_.rest([5, 4, 3, 2, 1]);=> [4, 3, 2, 1]源码: _.rest = _.tail = function(array, index, guard) { return slice.call(array, (index == null) || guard ? 阅读全文
posted @ 2012-04-15 22:36 himanhimao 阅读(228) 评论(0) 推荐(0) 编辑
摘要: Returns the last element of anarray. Passingnwill return the lastnelements of the array返回一个数组中的最后一个元素_.last([5, 4, 3, 2, 1]);=> 1源码: _.last = function(array, n, guard) { if ((n != null) && !guard) { return slice.call(array, Math.max(array.length - n, 0)); } else { return array[array... 阅读全文
posted @ 2012-04-15 22:31 himanhimao 阅读(246) 评论(0) 推荐(0) 编辑
摘要: initial_.initial(array, [n])Returns everything but the last entry of the array. Especially useful on the arguments object. Passnto exclude the lastnelements from the result.返回数组的所有元素,最后一个元素除外_.initial([5, 4, 3, 2, 1]);=> [5, 4, 3, 2] 源码: _.initial = function(array, n, guard) { return slice.call.. 阅读全文
posted @ 2012-04-15 22:24 himanhimao 阅读(287) 评论(0) 推荐(0) 编辑
摘要: _.first(array, [n])Alias:headReturns the first element of anarray. Passingnwill return the firstnelements of the array返回数组的第一个元素. 别名head1 _.first([5, 4, 3, 2, 1]);2 => 5源码: _.first = _.head = _.take = function(array, n, guard) { return (n != null) && !guard ? slice.call(array, 0, n) : arr 阅读全文
posted @ 2012-04-15 22:12 himanhimao 阅读(322) 评论(0) 推荐(0) 编辑