Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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)

AltStyle によって変換されたページ (->オリジナル) /