## DEV Community is a community of 662,276 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

# Daily Challenge #36 - Let's go for a run! dev.to staff
The hardworking team behind dev.to ❤️

Today's challenge requires you to calculate one's running pace.

For example:

runningPace(distance, time)
distance - A float with the number of kilometres
time - A string containing the time it took to travel the distance; it will always be minutes:seconds

The function should return the pace, "5:20" means it took 5 minutes and 20 seconds to travel one kilometre.

Happy Coding!

This challenge comes from jtauri on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!

## Discussion (9) Dane Hillard • Edited
``````def running_pace(distance, time):
minutes, seconds = [int(part) for part in time.split(':')]

total_seconds = minutes * 60 + seconds
seconds_per_km = total_seconds / distance

pace_minutes = int(seconds_per_km // 60)
pace_seconds = int(seconds_per_km % 60)
return f'{pace_minutes}:{pace_seconds:02d}'
`````` Here it goes!

``````runningPace = (distance, time) => {
const [minutes, seconds] = time.split(':').map((p) => parseInt(p));
const total = 60 * minutes + seconds;
const pace = total / distance;
return `\${Math.floor(pace / 60)}:\${('00' + Math.floor(pace % 60)).slice(-2)}`
}
`````` Python

``````def runningPace(distance, time):
time= time.split(':')
time=int(time)*60+int(time)
pace=int(time/distance)
m=pace//60
s=str(pace-(m*60))
if int(s)<10:    s='0'+str
return '%d:%s' %(m,s)
`````` Lisa Benmore

Not brilliant but...

``````function runningPace (distance, time) {
const twoDigits = num => String(num).length < 2 ? '0' + num : num;

const mins = parseInt(time.split(':'));
const secs = parseInt(time.split(':'));
const totalSecs = (mins * 60) + secs;

const timePerKm = totalSecs / parseInt(distance);

const results = [
twoDigits(Math.floor(timePerKm / 60)),
twoDigits(Math.round(timePerKm % 60))
];

return results.join(':');
}
`````` 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) * 60
var seconds = Number(timeArray) + 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;
}
`````` Héctor Pascual

Python :

``````def running_pace(distance, time):
time_split = time.split(':')
time_parsed = float(time_split)+float(time_split)/60
time_1km = time_parsed/distance #1 km divided speed in [km / m]
seconds_1_km = int(float(str(time_1km - int(time_1km))[1:])*60)
minutes_1_km = int(time_1km)
return f"{minutes_1_km}:{seconds_1_km}"
`````` Seiei Miyagi • Edited

Ruby <3

``````def runningPace(d, t)
t.split ?: |> map &:to_r |> then { @1 * 60 + @2 |> quo d |> divmod 60 |> then &"%02d:%02d".:% }
end
`````` Maneesh Kumar 🇮🇳

function runningPace(distance, time){
const dist = distance * 1000; //in meters
const timeInSecond =parseInt(time.split(':')) * 60 + parseInt(time.split(':')); //in seconds
const pace = dist / timeInSecond;
return pace

``````        }
`````` Ian Fabs

I know these don't get many likes, but I really appreciate these. Like really appreciate them!