js algorithm to determine an array of numbers appear many times

let arr = [11, 11, 2, 2, 5, 5, 5, 5, 3];
// Create a map, put every number and its corresponding number
let countObj = {};
for (i = 0; i <= arr.length - 1; i++) {
    let v = arr[i];
    if (countObj[v]) {
        countObj [i] ++;
    } else {
        countObj [i] = 1;
    }
}
// console.log(countObj); //{ '2': 2, '3': 1, '5': 4, '11': 2 }
for (let key in countObj) {
    if (countObj [key] === 1) {// is determined to occur in 1 in which the object attributes
        console.log(key);//3...
    }
}

Guess you like

Origin www.cnblogs.com/yt0817/p/11965860.html