Last active
January 18, 2022 07:52
-
-
Save evgeniyworkbel/a96be80ab7d79a2e3bdf5031292d2f1e to your computer and use it in GitHub Desktop.
Курс "Введение в программ-ие" Hexlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getTime = (min) => { | |
const newMinutes = min % 1440; | |
const hours = Math.floor(newMinutes / 60); | |
const minutes = newMinutes % 60; | |
const makeClockFrom = (num) => (num < 10 ? `0${num}` : `${num}`); | |
const hh = makeClockFrom(hours); | |
const mm = makeClockFrom(minutes); | |
const result = `${hh}:${mm}`; | |
return result; | |
}; | |
export default getTime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (rawMinutes) => { | |
const hours = Math.floor((rawMinutes / 60) % 24); | |
const formattedHours = hours >= 10 ? hours : `0${hours}`; | |
const minutes = rawMinutes % 60; | |
const formattedMinutes = minutes >= 10 ? minutes : `0${minutes}`; | |
return `${formattedHours}:${formattedMinutes}`; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Реализуйте и экспортируйте по умолчанию функцию, которая принимает на вход количество минут (прошедших с начала суток) и возвращает строку, являющуюся временем в формате чч:мм. Если количество минут содержит больше 24 часов (1 суток), то функция возвращает время, прошедшее с полуночи последних суток. | |
Примеры: | |
formattedTime(5); // 00:05 | |
formattedTime(15); // 00:15 | |
formattedTime(60); // 01:00 | |
formattedTime(67); // 01:07 | |
formattedTime(175); // 02:55 | |
formattedTime(600); // 10:00 | |
formattedTime(754); // 12:34 | |
formattedTime(1504); // 01:04 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment