js递归数组去重方法

2021-04-09 05:51
1919
0
1
JavaScript

本来是写一个找出重复元素的功能,限制不能使用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
关注公众号获取更多内容
vue打包报错No module factory available for dependency
js查找出现次数最多的字符并统计次数
暂无评论,快抢沙发吧
不支持canvas