Last active
May 5, 2021 10:02
-
-
Save alialaba/3da8855eb92e47c6b36e23baea7645c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@meekg33k Thanks. I really appreciate you