本来是写一个找出重复元素的功能,限制不能使用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
}