Skip to content

Instantly share code, notes, and snippets.

@alialaba
Last active May 5, 2021 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alialaba/3da8855eb92e47c6b36e23baea7645c0 to your computer and use it in GitHub Desktop.
Save alialaba/3da8855eb92e47c6b36e23baea7645c0 to your computer and use it in GitHub Desktop.
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]))
@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