Source code for the Dev.to article on recursion after factorials and Fibonacci
The following files demonstrate three different recursive functions, two simple and one more complicated. The simple examples are accompanied by there iterative counterparts.
- 1a: Factorial - iterative, using a for loop (factorial-i))
- 1b: Factorial - recursive (factorial-r)
- 2a: Fibonacci - iterative, using a for loop (fibonacci-i)
- 2b: Fibonacci - recursive (fibonacci-r)
- 3a: objectFlat - initial (objectFlat_initial)
- 3b: objectFlat (objectFlat)
To execute the tests for a specific function use the following command in a terminal session.
npm run <example>
where <example>
is something like 1a
or 3b
.
- Install Node.js
- No need to execute
npm install
because there are no 3rd-party dependencies.