Skip to content

Commit 83b4dd8

Browse files
authored
fix: cleanup CheckKishnamurthyNumber (#1626)
1 parent 894a46c commit 83b4dd8

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: Maths/CheckKishnamurthyNumber.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ const factorial = (n) => {
2424
const CheckKishnamurthyNumber = (number) => {
2525
// firstly, check that input is a number or not.
2626
if (typeof number !== 'number') {
27-
return new TypeError('Argument is not a number.')
27+
throw new TypeError('Argument is not a number.')
28+
}
29+
if (number === 0) {
30+
return false
2831
}
2932
// create a variable to store the sum of all digits factorial.
3033
let sumOfAllDigitFactorial = 0

Diff for: Maths/test/CheckKishnamurthyNumber.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { CheckKishnamurthyNumber } from '../CheckKishnamurthyNumber'
2+
3+
describe('CheckKishnamurthyNumber', () => {
4+
it.each([1, 2, 145, 40585])('returns true for %i', (num) => {
5+
expect(CheckKishnamurthyNumber(num)).toBe(true)
6+
})
7+
8+
it.each([0, 3, 4, 5, 100, 146, 1019823, -1])(
9+
'returns false for %i',
10+
(num) => {
11+
expect(CheckKishnamurthyNumber(num)).toBe(false)
12+
}
13+
)
14+
15+
it('should throw when input is not a number', () => {
16+
expect(() => CheckKishnamurthyNumber('2')).toThrowError()
17+
})
18+
})

0 commit comments

Comments
 (0)