Skip to content

Instantly share code, notes, and snippets.

@basekays
Created March 2, 2017 17:57
Show Gist options
  • Select an option

  • Save basekays/fd389b04df2f0f94ade12cb30bb0e77b to your computer and use it in GitHub Desktop.

Select an option

Save basekays/fd389b04df2f0f94ade12cb30bb0e77b to your computer and use it in GitHub Desktop.
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