Skip to content

Instantly share code, notes, and snippets.

@FelixLuciano
Created March 15, 2021 13:52
Show Gist options
  • Save FelixLuciano/97b09252c19041bdb001cd10ad20ae37 to your computer and use it in GitHub Desktop.
Save FelixLuciano/97b09252c19041bdb001cd10ad20ae37 to your computer and use it in GitHub Desktop.
rendezvous with cassidoo #187 - Interview question of the week
/**
* 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