您的位置:首页 > Web前端 > JavaScript

underscore.js _.intersect[Array]

2012-04-15 23:09 381 查看
Computes the list of values that are the intersection of all the arrays. Each value in the result is present in each of the arrays.

返回数组的交集

_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
=> [1, 2]


源码:

_.intersection = _.intersect = function(array) {
var rest = slice.call(arguments, 1);
return _.filter(_.uniq(array), function(item) {
return _.every(rest, function(other) {
return _.indexOf(other, item) >= 0;
});
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: