Back to Freecodecamp

Challenge 185: 2026 Winter Games Day 6: Figure Skating

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

latest1.8 KB
Original Source

--description--

Given an array of judge scores and optional penalties, calculate the final score for a figure skating routine.

The first argument is an array of 10 judge scores, each a number from 0 to 10. Remove the highest and lowest judge scores and sum the remaining 8 scores to get the base score.

Any additional arguments passed to the function are penalties. Subtract all penalties from the base score to get the final score.

--hints--

computeScore([10, 8, 9, 6, 9, 8, 8, 9, 7, 7], 1) should return 64.

js
assert.equal(computeScore([10, 8, 9, 6, 9, 8, 8, 9, 7, 7], 1), 64);

computeScore([10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) should return 80.

js
assert.equal(computeScore([10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), 80);

computeScore([10, 8, 9, 10, 9, 8, 8, 9, 10, 7], 1, 2, 1) should return 67.

js
assert.equal(computeScore([10, 8, 9, 10, 9, 8, 8, 9, 10, 7], 1, 2, 1), 67);

computeScore([8.0, 8.5, 9.0, 8.5, 9.0, 8.0, 9.0, 8.5, 9.0, 8.5], 0.5, 1.0) should return 67.5.

js
assert.equal(computeScore([8.0, 8.5, 9.0, 8.5, 9.0, 8.0, 9.0, 8.5, 9.0, 8.5], 0.5, 1.0), 67.5);

computeScore([6.0, 8.5, 7.0, 9.0, 7.5, 8.0, 6.5, 9.5, 7.0, 8.0], 1.5, 0.5, 0.5) should return 59.

js
assert.equal(computeScore([6.0, 8.5, 7.0, 9.0, 7.5, 8.0, 6.5, 9.5, 7.0, 8.0], 1.5, 0.5, 0.5), 59);

--seed--

--seed-contents--

js
function computeScore(judgeScores, ...penalties) {

  return judgeScores;
}

--solutions--

js
function computeScore(judgeScores, ...penalties) {
  const sortedScores = [...judgeScores].sort((a, b) => a - b);
  const baseScore = sortedScores.slice(1, 9).reduce((sum, s) => sum + s, 0);
  const totalPenalty = penalties.reduce((sum, p) => sum + p, 0);

  return baseScore - totalPenalty;
}