Skip to content

Instantly share code, notes, and snippets.

@alialaba
Last active May 5, 2021
Embed
What would you like to do?
const productNumber = (num) => {
let products = [num.length];
//forward pass
let forwardMultiple = 1;
for (let i = 0; i < num.length; i++) {
products[i] = forwardMultiple;
forwardMultiple *= num[i];
}
//backword pass
let backwordMultiple = 1;
for (let i = num.length - 1; i >= 0; i--) {
products[i] *= backwordMultiple;
backwordMultiple *= num[i];
}
return products;
}
console.log(productNumber([4, 5, 10, 2]))
@meekg33k
Copy link

meekg33k commented May 5, 2021

Hello @alialaba, congratulations, you are one of the winners of the $20 award 🎉🎉for Week 4 of #AlgorithmFridays.

Your solution was selected because it is optimal, well-explained through use of good commenting and also handles the edge case for when one of the numbers in the array is 0. Awesome stuff!

We will contact you between 24 - 48 hours for your award.

Congratulations once again and thanks for participating!

@alialaba
Copy link
Author

alialaba commented May 5, 2021

@meekg33k Thanks. I really appreciate you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment