-
Notifications
You must be signed in to change notification settings - Fork 14
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
resolving task no.4 with ugly code #22
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const convertTime = (motiveTime, clockStop, convertToMs, convertToHours) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function shouldn't have 4 params |
||
const convertedMotive = motiveTime.split(":"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable names don't say much. If I didn't see the values, I wouldn't know what is stored and assigned to them. |
||
const convertedClockStop = clockStop.split(":"); | ||
const msMotive = convertToMs(convertedMotive[0],convertedMotive[1]); | ||
const msClockStop = convertToMs(convertedClockStop[0],convertedClockStop[1]); | ||
const maxNum = Math.max(...[msMotive,msClockStop]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why create an array and use spread? Math.max(msMotive, msClockStop) would suffice. |
||
const minNum = Math.min(...[msClockStop,msMotive]); | ||
if(maxNum && minNum > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if this condition is evaluated as false? What would be returned then? |
||
const getFullTimeOfSleep = (maxNum - minNum); | ||
return convertToHours(getFullTimeOfSleep); | ||
} | ||
} | ||
const getMiliseconds = (h,m) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide default values, e.g. 0 |
||
return ((h*60*60+m*60)*1000); | ||
} | ||
|
||
function timeConversion(millisec) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There would be a better name, e.g. |
||
|
||
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)); |
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.
Good idea with taking output formatter as a function parameter. I'd give it a more meaningful name, though.
convertToHours
would be namedoutputFormatter
, for example.