js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Bit Counting #594

Closed RazvanBugoi closed 2 years ago

RazvanBugoi commented 2 years ago

https://www.codewars.com/kata/526571aae218b8ee490006f4/train/javascript

RazvanBugoi commented 2 years ago
const countBits = function(n) {
  const binary = n.toString(2)
  const arrOfOnes = binary.split("").filter( (element) => element == "1")

  return arrOfOnes.length
};