Created
December 9, 2016 00:48
-
-
Save gkucmierz/510925d76714ce79714f68768f1e813a to your computer and use it in GitHub Desktop.
Return pascal`s triangle to desired depth
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
| 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