LeetCode Problem - Link


Coming back to solving FizzBuzz after almost a decade brings back a lot of memories. I remember the FizzBuzz program was known to be very easy. It also teaches us the importance of ordering logical statements, there was a time when candidates get this wrong in interviews due to not paying attention to the order, quite a deceitful problem we have here.


Don't ever take for granted what FizzBuzz teaches you, embrace it. There is no shame in getting it wrong on your first try

/**
 * @param {number} n
 * @return {string[]}
 */


var getFizzBuzz = (n)=>{
    var isDivisibleBy5 = n % 5==0;
    var isDivisibleBy3 = n % 3==0;


    if (isDivisibleBy3 && isDivisibleBy5) {
        return "FizzBuzz"
    }
    else if (isDivisibleBy3) {
        return "Fizz"
    }
    else if (isDivisibleBy5) {
        return "Buzz"
    }
    return n.toString()
}


var fizzBuzz = function (n) {
    var finalArr = []
    for(var i=1;i<=n;i++){
        let fb = getFizzBuzz(i)
        finalArr.push(fb)
    }


    return finalArr
};