Codewards "Speed Control" challenge

The challenge:

My code so far

const gps = (distances, time ) =>{
  
  var arr = distances.map((e, i)=> distances[i+1]-distances[i]).slice(0, -1)
  var result = Math.floor(Math.max(...arr) * (3600/time))
  return distances.length <= 1 ? 0 : result
}

My code seems to produce the expected value for all the test cases I can see on the kata, although there’s still something wrong?

Oh brother, this is funny, the person who created the tests for this challenge kind of got things backwards :slight_smile:

Take a close look at how the gps function is being called in the sample test suite. Specifically, the order of the parameters. Let me know if you need a bigger hint. Bottom line, your code is fine, you just need to make a simple adjustment because the person who wrote the tests got it backwards.

P.S. Now that I look at it more, the instructions do include the function definition as gps(s, x) but I swear the seed code had it the other way around. Regardless, the first argument is the time and the second argument is the array of distances. Once you fix your function to reflect that, you will pass.

1 Like

Yeah that’s all it was, thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.