Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to Solve the Staircase Problem with 5 Lines of JavaScript

// N is total number of steps in the staircase
// stepTaken is a counter for steps taken in each combination
function steps(N, stepsTaken = 0) {

  if (stepsTaken === N) return 1;
  else if (stepsTaken > N) return 0;

  return steps(N,stepsTaken + 1) + steps(N,stepsTaken + 2) + steps(N,stepsTaken + 3);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: find result using type: mongoose.Schema.ObjectId, 
Javascript :: how to cut and paste an element in vanilla javascript 
Javascript :: get file name with extension netsuite suitescript 
Javascript :: stuck at "resvoling packages" 
Javascript :: react native uncaught error main has not been registered stackoverflow 
Javascript :: Colored tab in react Js MUI 
Javascript :: without the filter() method 
Javascript :: Unable to delete directory react native 
Javascript :: mvc return view with query string 
Javascript :: dropdown list trigger change with value jquery 
Javascript :: passing third parameter in context.commit vuejs 
Javascript :: math min js 
Javascript :: how to use script tag in javascript 
Javascript :: react component lifecycle 
Javascript :: verifier si chaien ade caractere apparait dans autre js 
Javascript :: react native avoid keyboard when multiline 
Javascript :: Could not resolve dependency: npm ERR! peer react@"^16.0.0" from react-acceptjs@0.1.2 
Javascript :: jquery datatable searchpane pagination not working 
Javascript :: v-smooth-scroll 
Javascript :: highcharts hide gaps 
Javascript :: how to convert html string to jsx element 
Javascript :: how to auto generate unique string in javascript 
Javascript :: Reversing the elements in an array-like object 
Javascript :: function solution(n) { } 
Javascript :: laravel , json Why it shows Cannot access offset of type string on string error 
Javascript :: add flag persmison to write file nodejs 
Javascript :: AngularJS two different actions in ng-submit 
Javascript :: Why am I getting an error, "ReferenceError: categories is not defined" in AngularJS 
Javascript :: Error thrown after ending the audio track / array of tracks in React Native Track Player 
Javascript :: debugJSON 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =