Last updated 4 years ago
Was this helpful?
const halvingSum = (n, step = 0, sum = 0) => { if ((n / (2 ** step)) >= 1) { return halvingSum(n, step + 1, sum + Math.floor(n / (2 ** step))); } return sum; };