JSFiddle - React, Tailwind, and code Playground
by Pritesh Patel
JavaScript
function productOfArrayEle(array){
let arr_below = [];
let len = array.length;
if(array.length<2){
return array;
}
let p = 1;
for(let i=0; i<len; ++i ){
arr_below[i] = p;
p *= array[i];
}
let arr_above = [];
for(let i = len-1; i>=0; --i){
arr_above[i]=p;
p *= array[i];
}
let result = [];
for(let i=0; i< len;i++){
result[i] = arr_below[i]*arr_above[i]
}
return result;
}
console.log(productOfArrayEle([1,2,3]));