Skip to content

Commit 83b4dd8

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

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Maths/CheckKishnamurthyNumber.js

Lines changed: 4 additions & 1 deletion
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
Lines changed: 18 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy