Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Created February 9, 2021 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicknyr/702acd1f647cebcf1cf7ff0594a49c9f to your computer and use it in GitHub Desktop.
Save Nicknyr/702acd1f647cebcf1cf7ff0594a49c9f to your computer and use it in GitHub Desktop.
CodeSignal: Valid Time
/*
Check if the given string is a correct time representation of the 24-hour clock.
Example
For time = "13:58", the output should be
validTime(time) = true;
For time = "25:51", the output should be
validTime(time) = false;
For time = "02:76", the output should be
validTime(time) = false.
*/
function validTime(time) {
let firstTwo = time.slice(0, 2);
let lastTwo = time.slice(3, 5);
if(firstTwo < 0 || firstTwo > 23) {
return false;
}
else if(lastTwo < 0 || lastTwo > 59) {
return false;
}
else {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment