mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
fix: throw error instead of returning it RailwayTimeConversion
(#1625)
This commit is contained in:
@ -18,7 +18,7 @@
|
||||
const RailwayTimeConversion = (timeString) => {
|
||||
// firstly, check that input is a string or not.
|
||||
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.
|
||||
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')
|
||||
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