js递归数组去重方法
本来是写一个找出重复元素的功能,限制不能使用es6,只能用一层循环,结果写着写着居然变成了去重方法,记录一下:
function findRepeat(arr) {
var result = []
const loop = (index) => {
if (index >= arr.length) {
return
}
if (!result.includes(arr[index])) {
result.push(arr[index])
}
index ++
loop(index)
}
loop(0)
return result
}


赏

支付宝微信
1
关注公众号获取更多内容
暂无评论,快抢沙发吧




