Add recursive factorial function (#85)

* Fix LinkedList

* Fix the prepend method for the LinkedList

* Fix the remove method for the MinHeap

* Correct a comment

* Fix BST removal method

* Fix the findEdge method of the graph

* Fix the value returned by DisjointSet union

* Add recursive factorial function
This commit is contained in:
m-maksyutin 2018-06-28 21:03:31 +03:00 committed by Oleksii Trekhleb
parent 65f08db5de
commit c5ed81d85e
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import factorialRecursive from '../factorialRecursive';
describe('factorialRecursive', () => {
it('should calculate factorial', () => {
expect(factorialRecursive(0)).toBe(1);
expect(factorialRecursive(1)).toBe(1);
expect(factorialRecursive(5)).toBe(120);
expect(factorialRecursive(8)).toBe(40320);
expect(factorialRecursive(10)).toBe(3628800);
});
});

View File

@ -0,0 +1,7 @@
/**
* @param {number} number
* @return {number}
*/
export default function factorialRecursive(number) {
return number > 1 ? number * factorialRecursive(number - 1) : 1;
}