Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sum index of an array javascript

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))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sum #index #array #javascript
ADD COMMENT
Topic
Name
2+6 =