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 a5945e3

Browse files
authored
fix: throw error instead of returning it (TheAlgorithms#1624)
1 parent c067a34 commit a5945e3

File tree

7 files changed

+19
-3
lines changed

7 files changed

+19
-3
lines changed

‎String/CheckFlatCase.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
const checkFlatCase = (varname) => {
1313
// firstly, check that input is a string or not.
1414
if (typeof varname !== 'string') {
15-
return new TypeError('Argument is not a string.')
15+
throw new TypeError('Argument is not a string.')
1616
}
1717

1818
const pat = /^[a-z]*$/

‎String/CheckKebabCase.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
const CheckKebabCase = (varName) => {
1111
// firstly, check that input is a string or not.
1212
if (typeof varName !== 'string') {
13-
return new TypeError('Argument is not a string.')
13+
throw new TypeError('Argument is not a string.')
1414
}
1515

1616
const pat = /(\w+)-(\w)([\w-]*)/

‎String/CheckPascalCase.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
const CheckPascalCase = (VarName) => {
1111
// firstly, check that input is a string or not.
1212
if (typeof VarName !== 'string') {
13-
return new TypeError('Argument is not a string.')
13+
throw new TypeError('Argument is not a string.')
1414
}
1515

1616
const pat = /^[A-Z][A-Za-z]*$/

‎String/test/CheckCamelCase.test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ describe('checkCamelCase', () => {
1515
const result = checkCamelCase(value)
1616
expect(result).toBe(false)
1717
})
18+
19+
it('should throw when input is not a string', () => {
20+
expect(() => checkCamelCase(100)).toThrowError()
21+
})
1822
})

‎String/test/CheckFlatCase.test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ describe('checkFlatCase function', () => {
1515
const actual = checkFlatCase('abcdefghijklmnopqrstuvwxyz')
1616
expect(actual).toBe(true)
1717
})
18+
19+
it('should throw when input is not a string', () => {
20+
expect(() => checkFlatCase(100)).toThrowError()
21+
})
1822
})

‎String/test/CheckKebabCase.test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ test('CheckKebabCase(The Algorithms) -> false', () => {
1111
const res = CheckKebabCase(word)
1212
expect(res).toBeFalsy()
1313
})
14+
15+
test('CheckKebabCase throws when input is not a string', () => {
16+
expect(() => CheckKebabCase(100)).toThrowError()
17+
})

‎String/test/CheckPascalCase.test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ test('CheckPascalCase(The Algorithms) -> false', () => {
1717
const res = CheckPascalCase(word)
1818
expect(res).toBeFalsy()
1919
})
20+
21+
test('CheckPascalCase throws when input is not a string', () => {
22+
expect(() => CheckPascalCase(100)).toThrowError()
23+
})

0 commit comments

Comments
(0)

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