LeetCode Problem - Link


An attempt at solving LeetCode's Number of Steps to Reduce a Number to Zero. It shouldn't take you more than a few minutes for you to get it right. Pretty easy.


Using A Simple While Loop

/**
 * @param {number} num
 * @return {number}
 */
var numberOfSteps = function(num) {
    let steps_counter = 0;
    while(num!==0){
        if(num%2==0){
            num=num/2
        }else{
            num -= 1
        }
        steps_counter += 1
    }
    return steps_counter
};