0
什么是最好的方式来过滤2d ARR和返回也2D,但只有唯一阵列作为元素:[[7,3,7],[7,7,3],[3,7,7],[3,7,7],[7,7,3],[7,3,7]]
应该返回[[7,3,7],[7,7,3],[3,7,7]]
?如何过滤2d数组?
什么是最好的方式来过滤2d ARR和返回也2D,但只有唯一阵列作为元素:[[7,3,7],[7,7,3],[3,7,7],[3,7,7],[7,7,3],[7,3,7]]
应该返回[[7,3,7],[7,7,3],[3,7,7]]
?如何过滤2d数组?
试试这个:
var uniques = function(items) {
var map = {};
return items.filter(function(item) {
return item in map ? false : map[item] = true;
});
};