Build the leaderboard for Nexo's coding tournament by chaining map(), filter(), and sort() with arrow functions without mutating the original data.
JavaScriptBeginnerWith Nexo
arrays · map-filter-sort · funciones-flecha
Statement
Your mission
In the Código con Criterio coding tournament organized by Nexo, you need to build the official leaderboard from the participants' raw scores. In modern JavaScript, the array methods map(), filter(), and sort() combined with arrow functions let you express this transformation, filtering, and sorting pipeline cleanly without manual loops or mutations on the input data.
Implement the solve(input) function, which receives a JSON object with three properties:
participantes: array of 0 to 100 objects, each with nombre (non-empty string of 1 to 40 characters; duplicate names are allowed) and puntaje (integer between 0 and 1000).
bonificacion: integer between 0 and 200.
puntajeMinimo: integer between 0 and 1200.
Apply the following stages in order:
Bonus (map()): transform each participant into a new object with their original nombre and their updated puntaje calculated as Math.min(1200, puntaje + bonificacion).
Qualification (filter()): keep only participants whose updated puntaje is >= puntajeMinimo.
Sorting (sort()): sort the qualified participants from highest to lowest updated score, preserving the original order in case of ties (using JavaScript's stable sort behavior).
Position numbering (map()): transform each sorted qualifier into an object with those exact three properties: posicion (consecutive integers starting at 1, even when ties occur), nombre, and puntaje (updated).
Return a JSON object with those exact five properties:
ranking: sorted array of { posicion, nombre, puntaje } objects.
totalParticipantes: original number of participants received.
totalClasificados: number of qualified participants.
puntajeMayor: updated score of the first-place participant in ranking, or null if no participant qualified.
promedioClasificados: Math.floor of the sum of qualified participants' updated scores divided by totalClasificados, or 0 if ranking is empty.
Rules and constraints
You must use map(), filter(), and sort(). A second map(), reduce(), Math.min(), and Math.floor() are allowed.
Do not use for, while, or for...of loops, recursion, classes, or Set.
Do not remove duplicate names or mutate the input.participantes array or its original objects.