JS Goodness : Calculate angle between Hour and Minute


 console.clear();  
 var h = 4;  
 var m = 30;  
 var result = calcAngle(h,m);  
 console.log("Angle between time "+h+":"+m +" is "+result +" degrees");  
 function calcAngle(h,m){  
  if(h===12) h=0;  
  if(m===60) m=0;  
  //how much hour angle has moved in one min  
  var hourAngleInMin = 360/(12*60);  
  //how much min angle has moved in one min  
  var minAngleInMin = 360/60;  
  //angle moved with reference to 12'clock  
  var movedHours = hourAngleInMin * (h*60 + m);  
  var movedMins = minAngleInMin*m;  
  //difference between them is the result  
  var result = Math.abs(movedHours - movedMins);  
  return result;   
 }  

Comments

Popular posts from this blog

Apache Airflow Wait Between Tasks

Groovy GoodNess – Converting a List to String

Java Spring Interview Questions