/** * 对于由简单类型数据组成的对象为元素组成的数组进行去重操作 * @params {Array} 需要去重的对象数组 * @returns {Array} 去重后的对象数组 */ function distinct(sourceArray) { var resultArray = []; var i, j, currentSource, currentResult; for (i = 0; i < sourceArray.length; i++) { currentSource = so
Collection Functions (Arrays or Objects) each _.each(list, iterator, [context]) 遍历list中的所有元素,如果传递了context参数,则把iterator绑定到context对象上.iterator的参数是 (value, key, list)).返回list以方便链式调用. _.each([1, 2, 3], alert); => alerts each number in turn... map
// Array Functions // --------------- // Get the first element of an array. Passing **n** will return the first N // values in the array. Aliased as `head` and `take`. The **guard** check // allows it to work with `_.map`. /* 返回array(数组)的第一个元素.传递 n参数
最劲项目需要用到js数组去重和交集的一些运算,我的数组元素个数可能到达1000以上,网上的实现方式都是2次循环,性能不适合我的需求,1000*1000那循环次数太多了,所以我这里采用对象object来做处理,用空间换时间,code 如下: ///集合取交集 Array.intersect = function () { var result = new Array(); var obj = {}; ; i < arguments.length; i++) { ; j < arguments[i