diff --git a/08_recursion_and_dynamic_programming/01_tripleStep.js b/08_recursion_and_dynamic_programming/01_tripleStep.js new file mode 100644 index 0000000..8f69a9c --- /dev/null +++ b/08_recursion_and_dynamic_programming/01_tripleStep.js @@ -0,0 +1,11 @@ +/* + A child is running up a staircase with n steps and can hop + either 1 step, 2 steps, or 3 steps at a time. Implement a method to + count how many possible ways the child can run up the stairs. +*/ + +function tripleStep(n) { + // Your code here +} + +module.exports = tripleStep; diff --git a/08_recursion_and_dynamic_programming/01_tripleStep.test.js b/08_recursion_and_dynamic_programming/01_tripleStep.test.js new file mode 100644 index 0000000..7e77ab4 --- /dev/null +++ b/08_recursion_and_dynamic_programming/01_tripleStep.test.js @@ -0,0 +1,18 @@ +'use strict'; + +const assert = require('chai').assert; +const tripleStep = require('./01_tripleStep'); + +describe('recursion and dynamic programming', function() { + describe('triple step', function() { + it('should find the number of ways to hop N steps', function() { + assert.equal(tripleStep(3), 4); + }) + it('should return 0 for non positive numbers', function() { + assert.equal(tripleStep(-2), 0); + }) + it('should return 1 for 0', function() { + assert.equal(tripleStep(0), 1); + }) + }) +})