Pascal's Triangle Generator Lab
Easy
20.0% Acceptance
In this lab, you will implement a function to generate the first numRows
of Pascal's Triangle. Pascal's triangle is a triangular array of numbers in which each number is the sum of the two numbers directly above it, as shown in the image below:
Your task is to write a function generate
that takes an integer numRows
and returns the first numRows
of Pascal's Triangle in a nested array format.
Examples
Example 1:
Input: numRows = 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
Example 2:
Input: numRows = 1
Output: [[1]]
Example 3:
Input: numRows = 3
Output: [[1],[1,1],[1,2,1]]
Constraints
1 <= numRows <= 30
Challenges
- Implement the
generate
function. - Export the
generate
function using ESM export.