Search
 
SCRIPT & CODE EXAMPLE
 

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))
Comment

PREVIOUS NEXT
Code Example
Javascript :: fetch post js 
Javascript :: auto scroll to view react-native 
Javascript :: append textarea jquery with value 
Javascript :: on scroll call function jquery 
Javascript :: how to disable button in jquery 
Javascript :: javascript find matching elements in two arrays 
Javascript :: nestjs set swagger api keys 
Javascript :: run jest test for a single file 
Javascript :: next-dev.js?3515:32 Warning: Prop `className` did not match. Server Client 
Javascript :: wait for 1 second in loop in javascript 
Javascript :: command to start a new react app using vite 
Javascript :: how to detect if an video is over js html 
Javascript :: get user input node js console 
Javascript :: moment format heure 
Javascript :: filter react 
Javascript :: js changing selected option by index 
Javascript :: express.js hello world 
Javascript :: js get element by innertext 
Javascript :: mongoose find multiple and delete 
Javascript :: html get form elements 
Javascript :: jquery timer countdown 
Javascript :: mongoose search 
Javascript :: Class constructor cannot be invoked without new 
Javascript :: discord.js create permanent invite 
Javascript :: javascript check if variable is empty 
Javascript :: react-router-dom routes 
Javascript :: %PDF-1.4 is response 
Javascript :: what is react 
Javascript :: javascript time of execution 
Javascript :: jspdf reduce size file 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =