Last active
July 27, 2024 20:03
-
-
Save michaelficarra/d9596dce09cd4de0470cca7524654a86 to your computer and use it in GitHub Desktop.
generate a row of Pascal's triangle in linear time and constant space
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
function* pascalsTriangleRow(row) { | |
let prev = 1; | |
for(let i = 1; i <= row; ++i) { | |
yield prev; | |
prev = (prev * (row - (i - 1))) / i; | |
} | |
yield 1; | |
} | |
Array.from(pascalsTriangleRow(19)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment