Skip to content

Instantly share code, notes, and snippets.

View allprod's full-sized avatar
💭
Figuring out the perfect variable name.

Mwenimpako P. S. allprod

💭
Figuring out the perfect variable name.
View GitHub Profile
function findProduct(arr) {
// First find the total product of all indeces
let totalProduct = arr[0];
for (let i = 1; i < arr.length; i++) {
totalProduct *= arr[i];
}
// Then, return a new array where each index is the
// product of all numbers, except for the current value of that index
// i.e. newArr[0] = arr[1] * arr[2] * arr[3]... arr[length-1];