Skip to content

Instantly share code, notes, and snippets.

@01Clarian
Created January 6, 2020 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 01Clarian/b1aee8813c7568e3d035d3413f61b359 to your computer and use it in GitHub Desktop.
Save 01Clarian/b1aee8813c7568e3d035d3413f61b359 to your computer and use it in GitHub Desktop.
index.js
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