Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const outputFormatter = (motiveTime, clockStop, convertToMs, convertToHours) => {
const convertedMotive = motiveTime.split(":");

Choose a reason for hiding this comment

The 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);
const minNum = Math.min(msClockStop,msMotive);
if(maxNum && minNum > 0) {

Choose a reason for hiding this comment

The 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);
}else {
return null;
}
}
const getMiliseconds = (h=0,m=0) => {
return ((h*60*60+m*60)*1000);
}

function formatTimeToString(millisec) {

const seconds = (millisec / 1000).toFixed(1);
const minutes = (millisec / (1000 * 60)).toFixed(1);
const hours = (millisec / (1000 * 60 * 60)).toFixed(1);

if (seconds < 60) {
return seconds + " Sec";
} else if (minutes < 60) {
return minutes + " Min";
} else {
return hours + " Hrs";
}
}
console.log(outputFormatter("5:15", "21:10", getMiliseconds,formatTimeToString));