Advertisement
Pijomir

Time To Walk

Jan 11th, 2024
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculateWalkingTime(steps, lengthInMeters, speed) {
  2.     let distance = steps * lengthInMeters / 1000;
  3.     let breaks = Math.floor(distance / 0.5) / 60;
  4.     let timeInSeconds = (distance / speed + breaks) * 3600;
  5.     let hours = String(Math.floor(timeInSeconds / 3600));
  6.     let minutes = String(Math.floor((timeInSeconds - (hours * 3600)) / 60));
  7.     let seconds = String((timeInSeconds - (hours * 3600) - (minutes * 60)).toFixed(0));
  8.  
  9.     return `${hours.padStart(2,'0')}:${minutes.padStart(2,'0')}:${seconds.padStart(2,'0')}`;
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement