-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solution #247
base: master
Are you sure you want to change the base?
solution #247
Conversation
src/getTime.js
Outdated
@@ -18,7 +18,25 @@ | |||
* @returns {string} - valid time | |||
*/ | |||
function getTime(str) { | |||
// write code here | |||
const hhmm = str.match(/\b\d{2}:\d{2}\b/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Твій regex метчить "неправильний" час, як то 24:50. Можна написати регулярний вираз так, щоб такі випадки не включались.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Переускладнювати код регулярки не хочу, щоб зберегти читабельність.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну дивись)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hhmm = str.match(/\b\d{2}:\d{2}\b/); | |
const matches = str.match(/\b\d{2}:\d{2}\b/); |
src/getTime.js
Outdated
@@ -18,7 +18,25 @@ | |||
* @returns {string} - valid time | |||
*/ | |||
function getTime(str) { | |||
// write code here | |||
const hhmm = str.match(/\b\d{2}:\d{2}\b/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hhmm = str.match(/\b\d{2}:\d{2}\b/); | |
const matches = str.match(/\b\d{2}:\d{2}\b/); |
src/getTime.js
Outdated
if (!hhmm) { | ||
return ''; | ||
} | ||
|
||
const hh = hhmm[0].substr(0, 2); | ||
const mm = hhmm[0].substr(3, 2); | ||
let time = ''; | ||
|
||
if (+hh > 23) { | ||
time = ''; | ||
} else if (+mm > 59) { | ||
time = ''; | ||
} else { | ||
time = hh + ':' + mm; | ||
} | ||
|
||
return time; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
этого не должно быть, мы работаем с регулярными выражениями
No description provided.