Created
January 6, 2020 13:33
-
-
Save 01Clarian/b1aee8813c7568e3d035d3413f61b359 to your computer and use it in GitHub Desktop.
index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function inclusiveArrayParamRecursive(startVal, endVal) { | |
if(startVal >= endVal) { | |
return [startVal] | |
} else { | |
const arr = inclusiveArrayParamRecursive(startVal, endVal - 1) | |
arr.push(endVal) | |
return arr | |
} | |
} | |
console.log('recursive inclusive array solution: ', inclusiveArrayParamRecursive(2, 6)) | |
// Base Case sets the loop paramenters to return the startVal. Once the start value equals end value we return the call stack to unwind. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment