DEV Community

Discussion on: Daily Challenge #36 - Let's go for a run!

Collapse
 
peter279k profile image
peter279k

Here is the simple solution with JavaScript:

function runningPace(distance, time)
{
  if (distance === 1) {
    return time;
  }

  var timeArray = time.split(':');
  var minute = Number(timeArray[0]) * 60
  var seconds = Number(timeArray[1]) + minute

  seconds = Math.floor(seconds / distance);

  minute = Math.floor(seconds / 60);
  var second = seconds - minute * 60;

  if (second >= 0 && second <= 9) {
    second = "0" + String(second);
  }

  return minute + ":" + second;
}