📜  数组的总和索引 javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:39.148000             🧑  作者: Mango

代码示例1
let countBits = function(n) {
    let binary = n.toString(2);
    let splitar = binary.split("");
    return splitar.reduce((a, b) => parseInt(a) + parseInt(b), 0)
};

console.log(countBits(0))
console.log(countBits(4))
console.log(countBits(7))
console.log(countBits(9))
console.log(countBits(10))