+ 1

I want to do this using one loop or no loop

function ProductOfArray(n,arr){ let str = ""; for (let i=0;i<n;i++){ let product = 1; for(let j=0;j<n;j++){ if(j!==i){ product*=arr[j]; } } str+=(product)+" "; } console.log(str); } ProductOfArray(5,[1,2,3,4,5]) ProductOfArray(3,[3,2,7]) output 120 60 40 30 24 14 21 6 dry run of first case i = 0 ==> 2*3*4*5 = 120 i = 1 ==> 1*3*4*5 = 60 i = 3 ==> 1*2*4*5 = 40 i = 4 ==> 1*2*3*5 = 30 i = 5 ==> 1*2*3*4 = 24 https://code.sololearn.com/cNx767W8ONZc

29th Jun 2022, 6:10 PM
TINKLE DASH
TINKLE DASH - avatar
2 Answers
+ 3
Int product = 1*2*3*4*5 // all elements After this for i: 0 to n product / arr[i] ita pseudo but i think you understand
29th Jun 2022, 7:41 PM
Мартин 😑🎵
Мартин 😑🎵 - avatar
+ 3
Мартин 😑🎵 thanks got it
29th Jun 2022, 7:51 PM
TINKLE DASH
TINKLE DASH - avatar