Recursive Staircase problem in JavaScript

Suppose we have the following problem −

There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 or 2 stairs at a time. We are required to count the number of ways, the person can reach the top.

We are required to write a JavaScript function that takes in a number n that denotes the number of stairs. The function should count and return the number of ways in which the stairs can be climbed.

Example

Following is the code −

const recursiveStaircase = (num = 10) => {
   if (num 

Output

Following is the output on console −

89
5
377
Updated on: 2020-12-11T08:57:58+05:30

718 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements