Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

65
Views
calculating running speed

My problem is a wrong result. I have a function this function has a distance and a time. The result I want to achieve is calculating running speed.

function runningPace(distance, time) {
  let result = time.replace(":", ".")
  let fl = parseFloat(result)
  let calc = fl / distance
  let num = calc.toFixed(2) + ''
  if(num.length === 1) {
    num = num + '.00'
  }
  let rep = num.replace('.', ':')
  console.log(distance, time, result, fl, calc, rep, num)
  
  return rep;
}

console.log(runningPace(5, '25:00')) // '5:00'
console.log(runningPace(4.99, '22:32')) // '4:30'

I wrote such a function. Sorry for the naming, I'll fix it when I get it fixed.

When I test this code, the output is:

expected '4:47' to equal '4:30'

'4:30' => four minute thirty second

How can I find a solution? Thanks everyone in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

convert anything in seconds:

function runningPace(dist, time)
  {
  let 
    [ mn, sc ] = time.split(':').map(Number)
  , fl         = Math.floor(((mn *60) + sc) / dist)
    ;
  sc = fl % 60
  mn = (fl - sc) / 60

  return `${mn}:${(sc<9)?'0'+sc:sc}`
}

console.log(runningPace( 5,    '25:00'))  // 5:00
console.log(runningPace( 4.99, '22:32'))  // 4:30

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!