2012年4月15日
摘要: A function to create flexibly-numbered lists of integers, handy foreachandmaploops.start, if omitted, defaults to0;stepdefaults to1. Returns a list of integers fromstarttostop, incremented (or decremented) bystep, exclusive.建立一个包含指定范围单元的数组 1 _.range(10); 2 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 3 _.ra 阅读全文
posted @ 2012-04-15 23:43 himanhimao 阅读(270) 评论(0) 推荐(0) 编辑
摘要: Returns the index of the last occurrence ofvaluein thearray, or-1if value is not present. Uses the nativelastIndexOffunction if possible返回值在数组中最后出现的位置,如果没有出现,返回-11 _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);2 => 4源码:1 _.lastIndexOf = function(array, item) {2 if (array == null) return -1;3 if (nat... 阅读全文
posted @ 2012-04-15 23:39 himanhimao 阅读(279) 评论(0) 推荐(0) 编辑
摘要: Returns the index at whichvaluecan be found in thearray, or-1if value is not present in thearray. Uses the nativeindexOffunction unless it's missing. If you're working with a large array, and you know that the array is already sorted, passtrueforisSortedto use a faster binary search.返回值在数组中首 阅读全文
posted @ 2012-04-15 23:35 himanhimao 阅读(446) 评论(0) 推荐(0) 编辑
摘要: Merges together the values of each of thearrayswith the values at the corresponding position. Useful when you have separate data sources that are coordinated through matching array indexes. If you're working with a matrix of nested arrays,zip.applycan transpose the matrix in a similar fashion将相对 阅读全文
posted @ 2012-04-15 23:30 himanhimao 阅读(313) 评论(0) 推荐(0) 编辑
摘要: Produces a duplicate-free version of thearray, using===to test object equality. If you know in advance that thearrayis sorted, passingtrueforisSortedwill run a much faster algorithm. If you want to compute unique items based on a transformation, pass aniteratorfunctio去除数组中重复的值,返回数组中所有唯一的值。别名unique_. 阅读全文
posted @ 2012-04-15 23:21 himanhimao 阅读(1001) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(415) 评论(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 阅读(315) 评论(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 阅读(296) 评论(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 阅读(523) 评论(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 阅读(212) 评论(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 阅读(225) 评论(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 阅读(243) 评论(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 阅读(284) 评论(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 阅读(321) 评论(0) 推荐(0) 编辑