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];
}
}
output.push(product);
}
return output;
};