curriculum/challenges/english/blocks/daily-coding-challenges-javascript/697a49e6ff50d756c9b69364.md
Given an array of five numbers, each representing the time (in seconds) it took a luger to complete a segment of a track, determine which segment had the fastest speed and what that speed was.
The track is divided into the following segments:
The first value in the given array corresponds to the time for segment 1, the second value to segment 2, and so on.
To calculate the speed (in meters per second) for a segment, divide the distance by the time.
Return "The luger's fastest speed was X m/s on segment Y.". Where X is the fastest speed, rounded to two decimal places, and Y is the segment number where the fastest speed occurred.
getFastestSpeed([9.523, 8.234, 10.012, 9.001, 7.128]) should return "The luger's fastest speed was 35.07 m/s on segment 5."
assert.equal(getFastestSpeed([9.523, 8.234, 10.012, 9.001, 7.128]), "The luger's fastest speed was 35.07 m/s on segment 5.");
getFastestSpeed([9.381, 7.417, 9.912, 8.815, 7.284]) should return "The luger's fastest speed was 37.75 m/s on segment 2."
assert.equal(getFastestSpeed([9.381, 7.417, 9.912, 8.815, 7.284]), "The luger's fastest speed was 37.75 m/s on segment 2.");
getFastestSpeed([8.890, 7.601, 9.093, 8.392, 6.912]) should return "The luger's fastest speed was 38.49 m/s on segment 3."
assert.equal(getFastestSpeed([8.890, 7.601, 9.093, 8.392, 6.912]), "The luger's fastest speed was 38.49 m/s on segment 3.");
getFastestSpeed([8.490, 7.732, 10.103, 8.489, 6.840]) should return "The luger's fastest speed was 37.69 m/s on segment 1."
assert.equal(getFastestSpeed([8.490, 7.732, 10.103, 8.489, 6.840]), "The luger's fastest speed was 37.69 m/s on segment 1.");
getFastestSpeed([8.204, 7.230, 9.673, 7.645, 6.508]) should return "The luger's fastest speed was 39.24 m/s on segment 4."
assert.equal(getFastestSpeed([8.204, 7.230, 9.673, 7.645, 6.508]), "The luger's fastest speed was 39.24 m/s on segment 4.");
function getFastestSpeed(times) {
return times;
}
function getFastestSpeed(times) {
const distances = [320, 280, 350, 300, 250];
let fastestSpeed = 0;
let fastestSegment = 0;
for (let i = 0; i < times.length; i++) {
const speed = distances[i] / times[i];
if (speed > fastestSpeed) {
fastestSpeed = speed;
fastestSegment = i + 1;
}
}
return `The luger's fastest speed was ${fastestSpeed.toFixed(2)} m/s on segment ${fastestSegment}.`;
}