Created
March 15, 2021 13:52
-
-
Save FelixLuciano/97b09252c19041bdb001cd10ad20ae37 to your computer and use it in GitHub Desktop.
rendezvous with cassidoo #187 - Interview question of the week
This file contains hidden or 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
/** | |
* From: https://buttondown.email/cassidoo/archive/5c50e780-c247-4167-a99d-99f4b9656011 | |
* @param {number} rowIndex Row index | |
* @returns {number[]} Values in that row of Pascal’s Triangle. | |
* @example | |
* $ pascals(3) | |
* -> [1, 3, 3, 1] | |
*/ | |
function pascals (rowIndex) { | |
let row = [1] | |
for (let next = []; row.length <= rowIndex; row = next, next = []) | |
for (let j = 0; j <= row.length; j++) | |
next[j] = (row[j-1] || 0) + (row[j] || 0) | |
return row | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment