merge: WhileLoopFactorial: Optimize and add tests (#992)

* Optimised the factorial function.

There was previously an unnecessary check for if the number was 0 or 1.

* Create WhileLoopFactorial.test.js

The test was not present previously.

* result *= num

* Update WhileLoopFactorial.test.js

* testFactorial function

* Space for formatting.

* should fix the formatting issues. I was having trouble with npx standard, so I just used the online verifier at https://standardjs.com/demo.html
This commit is contained in:
merelymyself
2022-04-22 00:28:29 +08:00
committed by GitHub
parent 1e0dd1c44f
commit 9513bcd77a
2 changed files with 16 additions and 6 deletions

View File

@@ -0,0 +1,12 @@
import { factorialize } from '../WhileLoopFactorial'
function testFactorial (n, expected) {
test('Testing on ' + n + '!', () => {
expect(factorialize(n)).toBe(expected)
})
}
testFactorial(3, 6)
testFactorial(7, 5040)
testFactorial(0, 1)
testFactorial(12, 479001600)