Created
March 2, 2017 17:57
-
-
Save basekays/fd389b04df2f0f94ade12cb30bb0e77b to your computer and use it in GitHub Desktop.
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
| var generate = function(numRows) { | |
| var triangle = []; | |
| var firstRow = [1]; | |
| var secondRow = [1, 1]; | |
| if (numRows === 1) { | |
| return triangle.push(firstRow); | |
| } else if (numRows === 2) { | |
| triangle.push(firstRow); | |
| return triangle.push(secondRow); | |
| } | |
| while (triangle.length < numRows) { | |
| var newRow = []; | |
| newRow[0] = 1; | |
| newRow[numRows.length - 1] = 1; | |
| for (var i = 1; i < numRows.length - 1; i++) { | |
| newRow[i] = | |
| } | |
| } | |
| return triangle; | |
| } | |
| console.log(generate(2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment