Wrong output, I get four commas in fron of the array

Given an integer array nums , return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]

So I wrote:

var productExceptSelf = function(nums) {
    let i; 
    let j; 
    var output = new Array(nums.length); 
    for(i=0; i<nums.length; i++){
            let product = 1; 
        for(j=0; j<nums.length; j++){
            if(j != i){
                product *= nums[j]; 
    return output; 

What does that line do?

it looks to me you initialized an array output with a set size, but instead of filling those up, you pushed your products as additional answers. This effectively gives you an answer array with n number of undefined followed by n number of products, where n is nums.length

Creates a new array the same length as the one sent in as a parameter.

Right, and what is inside that array?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.