Sollicitatievraag bij Rue Gilt Groupe

Write a function in javascript that determines the angle between the second and hour hand on a clock given a time.

Antwoorden op sollicitatievragen

Anoniem

8 okt 2013

I'm no JS expert, but first of all I think they'd ask for the minute and hour hands, and not the second hand, otherwise you can't get an accurate measurement of the hour hand degrees: //Difference between minutes and hour hands in degrees function translateTime(minutes,hours) { var degreesMin = (minutes/60) * 360; var degreesHr = (((hours%12)/12)+(minutes/60)*(1/12)) * 360 return (degreesHr-degreesMin)%360; } var output = translateTime(30,3); console.log(output);

1

Anoniem

25 sep 2019

I know this is an old question - but timeless! For the difference in the angle between the hour and minutes would be: function translateTime(minutes,hours) { degreesMin = (minutes/60) * 360; degreesHr = (hours/12) * 360; return Math.abs(degreesHr-degreesMin); } console.log(translateTime(30,3)); // 90 console.log(translateTime(5,11)); // 300