Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.9 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
697a49e6ff50d756c9b69361 Challenge 184: 2026 Winter Games Day 5: Cross-Country Skiing 28 challenge-184

--description--

Given an array of finish times for a cross-country ski race, convert them into times behind the winner.

  • Given times are strings in "H:MM:SS" format.
  • Given times will be in order from fastest to slowest.
  • The winners time (fastest time) should correspond to "0".
  • Each other time should show the time behind the winner, in the format "+M:SS".

For example, given ["1:25:32", "1:26:10", "1:27:05"], return ["0", "+0:38", "+1:33"].

--hints--

getRelativeResults(["1:25:32", "1:26:10", "1:27:05"]) should return ["0", "+0:38", "+1:33"].

assert.deepEqual(getRelativeResults(["1:25:32", "1:26:10", "1:27:05"]), ["0", "+0:38", "+1:33"]);

getRelativeResults(["1:00:01", "1:00:05", "1:00:10"]) should return ["0", "+0:04", "+0:09"].

assert.deepEqual(getRelativeResults(["1:00:01", "1:00:05", "1:00:10"]), ["0", "+0:04", "+0:09"]);

getRelativeResults(["1:10:06", "1:10:23", "1:10:48", "1:12:11"]) should return ["0", "+0:17", "+0:42", "+2:05"].

assert.deepEqual(getRelativeResults(["1:10:06", "1:10:23", "1:10:48", "1:12:11"]), ["0", "+0:17", "+0:42", "+2:05"]);

getRelativeResults(["0:49:13", "0:49:15", "0:50:14", "0:51:30", "0:51:58", "0:52:16", "0:53:12", "0:53:31", "0:56:19", "1:02:20"]) should return ["0", "+0:02", "+1:01", "+2:17", "+2:45", "+3:03", "+3:59", "+4:18", "+7:06", "+13:07"].

assert.deepEqual(getRelativeResults(["0:49:13", "0:49:15", "0:50:14", "0:51:30", "0:51:58", "0:52:16", "0:53:12", "0:53:31", "0:56:19", "1:02:20"]), ["0", "+0:02", "+1:01", "+2:17", "+2:45", "+3:03", "+3:59", "+4:18", "+7:06", "+13:07"]);

getRelativeResults(["2:01:15", "2:10:45", "2:10:53", "2:11:04", "2:11:55", "2:13:27", "2:14:30", "2:15:10"]) should return ["0", "+9:30", "+9:38", "+9:49", "+10:40", "+12:12", "+13:15", "+13:55"].

assert.deepEqual(getRelativeResults(["2:01:15", "2:10:45", "2:10:53", "2:11:04", "2:11:55", "2:13:27", "2:14:30", "2:15:10"]), ["0", "+9:30", "+9:38", "+9:49", "+10:40", "+12:12", "+13:15", "+13:55"]);

--seed--

--seed-contents--

function getRelativeResults(results) {

  return results;
}

--solutions--

function getRelativeResults(results) {
  const timeToSeconds = (timeStr) => {
    const [hours, minutes, seconds] = timeStr.split(':').map(Number);
    return hours * 3600 + minutes * 60 + seconds;
  };

  const secondsToTimeFormat = (secs) => {
    const mins = Math.floor(secs / 60);
    const secsRemainder = secs % 60;
    return `+${mins}:${String(secsRemainder).padStart(2, '0')}`;
  };

  const winnerSeconds = timeToSeconds(results[0]);

  return results.map((time, index) => {
    if (index === 0) return '0';
    const currentSeconds = timeToSeconds(time);
    const difference = currentSeconds - winnerSeconds;
    return secondsToTimeFormat(difference);
  });
}