Pascal's Triangle
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write pascal(rows): return the first rows rows of Pascal's triangle, as an array of arrays. The first row is [1]; each row has one more number than the one before, starts and ends with 1, and every number in between is the sum of the two numbers above it. rows is a whole number, 0 or more, and pascal(0) is an empty array. For example, pascal(4) is [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]].
Your code must pass
- Builds the first few rows
- Adds the two numbers above for each inner number
- Returns exactly the number of rows asked for
- Returns an empty array for 0 rows