当前位置:网站首页>JS to find the character that appears three times in the string

JS to find the character that appears three times in the string

2022-04-23 17:03:00 Eli-sun

let str = 'abvfFiioipuipplljlnnyfsaa'
    let arr = str.split('')
    console.log('111',arr);
    arr = arr.sort()
    console.log('222',arr);
    let temp = []
    for(var i=0;i<arr.length;i++){
        let sum = 0
        for(var j=0;j<arr.length;j++){
            if(arr[i] === arr[j]){
                sum+=1
            }
        }
        if(sum === 3){
            temp.push(arr[i])
            temp = [...new Set(temp)]
        }
    }
    console.log('333',temp); //  ['a', 'l', 'p']

版权声明
本文为[Eli-sun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554289577.html