Skip to content

Instantly share code, notes, and snippets.

@brittanmcg
Created May 4, 2020 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brittanmcg/f57b3ec3f8609929fbc07c5cd6596f20 to your computer and use it in GitHub Desktop.
Save brittanmcg/f57b3ec3f8609929fbc07c5cd6596f20 to your computer and use it in GitHub Desktop.
Calculates degrees between clock hands
function calculateAngle(h, m) {
const minuteDeg = 6;
const hourTimesFive = h === 12 ? 0 : h * 5;
const minuteMinusHoursTimesFive = m - hourTimesFive;
let degrees = minuteMinusHoursTimesFive * minuteDeg;
if (Math.sign(degrees) === -1) {
degrees = -degrees; // if negative degrees, set to positive
}
return degrees;
}
@brittanmcg
Copy link
Author

  1. My favorite React feature is how intuitively you can write your components. If written well, you should be able to get a pretty good idea of what the component does based on the props that are available to it.

  2. As far as websites go, I used to work on a monetization funnel that would get 10's of thousands of visitors per day. My role was to come up with different ideas to a/b test and implement these ideas in the monetization funnel. We had about 14 people on that team.

  3. I define high quality code as being easy to reason about and read. Code should not be clever. You should be able to read through it and not have to expend too much mental energy going back and forth from different areas of the code.

  4. How I would troubleshoot a problem would be to first reproduce the issue locally. If I can do that it makes it much easier to debug and see what the problem is. Sometimes you cannot do that, in that case assuming that we have adequate logging infrastructure in place, I would dig through the logs to see if anything looked out of order.

@mehmetkoc182
Copy link

Some clocks also move the hour hand slightly towards the next hour according to the minute passed.
How would you incorporate that into your function?

I.E. (12, 30) input should actually output 165 instead of 180.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment