From 2e3945d0eceb29b32b74c60505f244a50d846e02 Mon Sep 17 00:00:00 2001 From: Chester97 Date: Tue, 22 Oct 2019 19:45:47 +0200 Subject: [PATCH 1/2] resolving task no.4 with ugly code --- app.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..60c81cc --- /dev/null +++ b/app.js @@ -0,0 +1,34 @@ +const convertTime = (motiveTime, clockStop, convertToMs, convertToHours) => { + const convertedMotive = motiveTime.split(":"); + const convertedClockStop = clockStop.split(":"); + const msMotive = convertToMs(convertedMotive[0],convertedMotive[1]); + const msClockStop = convertToMs(convertedClockStop[0],convertedClockStop[1]); + const maxNum = Math.max(...[msMotive,msClockStop]); + const minNum = Math.min(...[msClockStop,msMotive]); + if(maxNum && minNum > 0) { + const getFullTimeOfSleep = (maxNum - minNum); + return convertToHours(getFullTimeOfSleep); + } +} +const getMiliseconds = (h,m) => { + return ((h*60*60+m*60)*1000); +} + +function timeConversion(millisec) { + + const seconds = (millisec / 1000).toFixed(1); + const minutes = (millisec / (1000 * 60)).toFixed(1); + const hours = (millisec / (1000 * 60 * 60)).toFixed(1); + const days = (millisec / (1000 * 60 * 60 * 24)).toFixed(1); + + if (seconds < 60) { + return seconds + " Sec"; + } else if (minutes < 60) { + return minutes + " Min"; + } else if (hours < 24) { + return hours + " Hrs"; + } else { + return days + " Days" + } +} +console.log(convertTime("5:15", "21:10", getMiliseconds,timeConversion)); \ No newline at end of file From fc8e8bcb42413f000966e75f830749cf94137ab5 Mon Sep 17 00:00:00 2001 From: Chester97 Date: Tue, 22 Oct 2019 21:12:46 +0200 Subject: [PATCH 2/2] changing names, delete days from formatFunc --- app.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index 60c81cc..9713274 100644 --- a/app.js +++ b/app.js @@ -1,34 +1,33 @@ -const convertTime = (motiveTime, clockStop, convertToMs, convertToHours) => { +const outputFormatter = (motiveTime, clockStop, convertToMs, convertToHours) => { const convertedMotive = motiveTime.split(":"); const convertedClockStop = clockStop.split(":"); const msMotive = convertToMs(convertedMotive[0],convertedMotive[1]); const msClockStop = convertToMs(convertedClockStop[0],convertedClockStop[1]); - const maxNum = Math.max(...[msMotive,msClockStop]); - const minNum = Math.min(...[msClockStop,msMotive]); + const maxNum = Math.max(msMotive,msClockStop); + const minNum = Math.min(msClockStop,msMotive); if(maxNum && minNum > 0) { const getFullTimeOfSleep = (maxNum - minNum); return convertToHours(getFullTimeOfSleep); + }else { + return null; } } -const getMiliseconds = (h,m) => { +const getMiliseconds = (h=0,m=0) => { return ((h*60*60+m*60)*1000); } -function timeConversion(millisec) { +function formatTimeToString(millisec) { const seconds = (millisec / 1000).toFixed(1); const minutes = (millisec / (1000 * 60)).toFixed(1); const hours = (millisec / (1000 * 60 * 60)).toFixed(1); - const days = (millisec / (1000 * 60 * 60 * 24)).toFixed(1); if (seconds < 60) { return seconds + " Sec"; } else if (minutes < 60) { return minutes + " Min"; - } else if (hours < 24) { - return hours + " Hrs"; } else { - return days + " Days" - } + return hours + " Hrs"; + } } -console.log(convertTime("5:15", "21:10", getMiliseconds,timeConversion)); \ No newline at end of file +console.log(outputFormatter("5:15", "21:10", getMiliseconds,formatTimeToString)); \ No newline at end of file