curriculum/challenges/english/blocks/daily-coding-challenges-javascript/697a49e9860d24853adef67c.md
Given an array representing the weights of the athletes on a bobsled team and a number representing the weight of the bobsled, determine whether the team is eligible to race.
The bobsled (sled by itself) must have a minimum weight of:
The total weight of the bobsled (athletes plus sled) must not exceed:
Return "Eligible" if the team meets all the requirements, or "Not Eligible" if the team fails to meet one or more of the requirements.
checkEligibility([78], 165) should return "Eligible".
assert.equal(checkEligibility([78], 165), "Eligible");
checkEligibility([80], 160) should return "Not Eligible".
assert.equal(checkEligibility([80], 160), "Not Eligible");
checkEligibility([80], 170) should return "Not Eligible".
assert.equal(checkEligibility([80], 170), "Not Eligible");
checkEligibility([85, 90], 170) should return "Eligible".
assert.equal(checkEligibility([85, 90], 170), "Eligible");
checkEligibility([85, 95], 168) should return "Not Eligible".
assert.equal(checkEligibility([85, 95], 168), "Not Eligible");
checkEligibility([112, 97], 185) should return "Not Eligible".
assert.equal(checkEligibility([112, 97], 185), "Not Eligible");
checkEligibility([110, 102, 90, 106], 222) should return "Eligible".
assert.equal(checkEligibility([110, 102, 90, 106], 222), "Eligible");
checkEligibility([106, 99, 90, 88], 205) should return "Not Eligible".
assert.equal(checkEligibility([106, 99, 90, 88], 205), "Not Eligible");
checkEligibility([106, 99, 103, 96], 227) should return "Not Eligible".
assert.equal(checkEligibility([106, 99, 103, 96], 227), "Not Eligible");
function checkEligibility(athleteWeights, sledWeight) {
return athleteWeights;
}
function checkEligibility(athleteWeights, sledWeight) {
const teamSize = athleteWeights.length;
const rules = {
1: { minSled: 162, maxTotal: 247 },
2: { minSled: 170, maxTotal: 390 },
4: { minSled: 210, maxTotal: 630 }
};
const { minSled, maxTotal } = rules[teamSize];
const athleteTotal = athleteWeights.reduce((sum, w) => sum + w, 0);
const totalWeight = athleteTotal + sledWeight;
if (sledWeight < minSled) {
return "Not Eligible";
}
if (totalWeight > maxTotal) {
return "Not Eligible";
}
return "Eligible";
}