Good afternoon! Here's our prompt for today.
In a certain kind of pyramid, each number in a row is the sum of the two numbers directly above it (arranged in a triangular fashion).

Given an integer n
, return the first of the n
rows of the pyramid.
For example, if n = 5
, then the first 5 rows of the pyramid will be represented in the array form as follows,
SNIPPET
1[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]
Constraints
- 1 <=
n
<= 30
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
39
var assert = require('assert');
​
function pyramidPuzzle(n) {
return;
}
​
try {
assert.deepEqual(pyramidPuzzle(5), [
[1],
[1, 1],
[1, 2, 1],
[1, 3, 3, 1],
[1, 4, 6, 4, 1]
]);
console.log('PASSED: ' + "`pyramidPuzzle(5)` should return `[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]`");
} catch (err) {
console.log(err);
}
​
try {
assert.deepEqual(pyramidPuzzle(1), [
[1]
]);
console.log('PASSED: ' + "`pyramidPuzzle(1)` should return `[[1]]`");
} catch (err) {
console.log(err);
}
​
try {
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
We'll now take you through what you need to know.
How do I use this guide?