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 1 commit
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
34 changes: 34 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const convertTime = (motiveTime, clockStop, convertToMs, convertToHours) => {

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 named outputFormatter, for example.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function shouldn't have 4 params

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]);

Choose a reason for hiding this comment

The 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) {

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);
}
}
const getMiliseconds = (h,m) => {

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There would be a better name, e.g. formatTimeToString.


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));