Simple JavaScript Question


  • 0
    P
    /**
     * @param {number} n
     * @return {string[]}
     */
    var fizzBuzz = function(n) {
        var arr=[];
        for(let i=1;i<=n;i++){
                if(i%15===0)
                         arr.push("FizzBuzz");
               else if(i%5===0)
                         arr.push("Buzz");
                else if(i%3===0)
                         arr.push("Fizz");
                else 
                arr.push(i.toString());
        }
        return arr;
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.