mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 19:17:33 +08:00
fix: throw error instead of returning it RailwayTimeConversion
(#1625)
This commit is contained in:
@ -18,7 +18,7 @@
|
|||||||
const RailwayTimeConversion = (timeString) => {
|
const RailwayTimeConversion = (timeString) => {
|
||||||
// firstly, check that input is a string or not.
|
// firstly, check that input is a string or not.
|
||||||
if (typeof timeString !== 'string') {
|
if (typeof timeString !== 'string') {
|
||||||
return new TypeError('Argument is not a string.')
|
throw new TypeError('Argument is not a string.')
|
||||||
}
|
}
|
||||||
// split the string by ':' character.
|
// split the string by ':' character.
|
||||||
const [hour, minute, secondWithShift] = timeString.split(':')
|
const [hour, minute, secondWithShift] = timeString.split(':')
|
||||||
|
@ -19,3 +19,7 @@ test('The RailwayTimeConversion of 11:20:00PM is 23:20:00', () => {
|
|||||||
const res = RailwayTimeConversion('11:20:00PM')
|
const res = RailwayTimeConversion('11:20:00PM')
|
||||||
expect(res).toEqual('23:20:00')
|
expect(res).toEqual('23:20:00')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('The RailwayTimeConversion throws when input is not a string', () => {
|
||||||
|
expect(() => RailwayTimeConversion(1120)).toThrowError()
|
||||||
|
})
|
||||||
|
Reference in New Issue
Block a user