Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created December 9, 2016 00:48
Show Gist options
  • Select an option

  • Save gkucmierz/510925d76714ce79714f68768f1e813a to your computer and use it in GitHub Desktop.

Select an option

Save gkucmierz/510925d76714ce79714f68768f1e813a to your computer and use it in GitHub Desktop.
Return pascal`s triangle to desired depth
function pascalsTriange(depth) {
let last = [1];
let res = [];
for (let i = 0; i < depth; i++) {
let n = [];
for (let j = 0; j < i + 1; j++) {
n[j] = (last[j-1] || 0) + (last[j] || 0);
}
res.push(n);
last = n;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment