Last active
November 23, 2015 21:27
-
-
Save csim/10286010 to your computer and use it in GitHub Desktop.
Clock Problem Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var angle = function(hour, minute) { | |
var hourAngle = parseFloat(hour * 30); | |
// take into account the movement of the hour hand between hours | |
hourAngle = hourAngle + parseFloat((minute / 60) * 5); | |
var minuteAngle = parseFloat(minute * 6); | |
var angle = Math.abs(hourAngle - minuteAngle); | |
return (angle > 180) ? 360 - angle : angle; | |
}; | |
alert(angle(3, 0)); | |
alert(angle(3, 10)); | |
alert(angle(3, 30)); | |
alert(angle(3, 40)); | |
alert(angle(8, 33)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment