Hi there! I’m working on the Gold Medal Metrics project, and can´t figure out why my code does not pass the test. I have taken a look at the solution code, that basically does the same thing, although in a different way. Any clarification would be much appreciated! Thanks in advance!
Task description:
bestYear
Takes an argument, the name of a country. Returns the SQL command that will retrieve the
year
that country won the most Olympic gold medals, and how many medals were won, aliased to the namecount
.
My code:
const bestYear = country => {
return `SELECT year, COUNT(*) AS count FROM GoldMedal WHERE country = '${country} GROUP BY 1 ORDER BY 2 DESC LIMIT 1';`;
};
Test output:
Solution Code:
const countryBestWithCount = (bestThing, country) => {
if (['year', 'discipline', 'sport', 'event'].includes(bestThing)) {
return `SELECT ${bestThing}, COUNT(*) AS count FROM GoldMedal WHERE country = '${country}' GROUP BY ${bestThing} ORDER BY COUNT(*) DESC LIMIT 1;`;
}
return null;
};
/*
Returns a SQL query string that will find the year where the given country
won the most medals, along with the number of medals aliased to 'count'.
*/
const bestYear = country => {
return countryBestWithCount('year', country);
Note, that the solution code makes use of an additional function ( countryBestWithCount), but the final query is the same.
Thanks again!