/**
* 移除数组中的相同元素
*
* @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;
(lodash_gcy)unique—移除数组中的相同元素
最新推荐文章于 2023-03-30 19:42:02 发布