您的位置:首页 > 产品设计 > UI/UE

(lodash_gcy)unique—移除数组中的相同元素

2017-02-28 23:33 253 查看
/**
* 移除数组中的相同元素
*
* @returns {array} 返回处理后的数组
*
* @example
*
* [1,2,3,1,2].unique();
* //=> [1,2,3]
* */

function unique() {
let temArr = [];
this.forEach((item)=>{
if (!(temArr.indexOf(item) + 1)) {
//indexOf无法判断NaN的情况
if (Number.isNaN(item)){
if (!temArr.hasNaN()) temArr.push(item)
}else temArr.push(item)
}
});
return temArr
}

module.exports = unique;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: