Back to Freecodecamp

Challenge 187: 2026 Winter Games Day 8: Luge

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/697a49e6ff50d756c9b69364.md

latest2.6 KB
Original Source

--description--

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:

  • Segment 1: 320 meters
  • Segment 2: 280 meters
  • Segment 3: 350 meters
  • Segment 4: 300 meters
  • Segment 5: 250 meters

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.

--hints--

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."

js
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."

js
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."

js
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."

js
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."

js
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.");

--seed--

--seed-contents--

js
function getFastestSpeed(times) {

  return times;
}

--solutions--

js
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}.`;
}