Javascript: Pascal's Triangle

JS: Arrays
Last update: 29 Apr 11:21
0
Students

Pascal's triangle is an infinite table of binomial coefficients having a triangular shape. This triangle has 1's at the top and both diagonal edges. Each number is equal to the sum of two numbers above it. The rows of the triangle are symmetric to the vertical axis.

0:      1
1:     1 1
2:    1 2 1
3:   1 3 3 1
4:  1 4 6 4 1

solution.js

Write and export as default the generate function that returns a specified row of Pascal's triangle as an array.

Example:

generate(1); // [1, 1]
generate(4); // [1, 4, 6, 4, 1]

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests