Study Recommender with map, filter, find, some, and every
Build an educational resource recommender with Nexo in JavaScript combining filter(), map(), find(), some(), and every() without mutating the original catalog.
Nexo is building the Código con Criterio study recommender to suggest pending learning resources based on the chosen category and each student's available time.
Implement the solve(input) function, which receives an object with:
recursos: array of 0 to 100 objects, where each resource has:
id: unique integer between 1 and 10000.
titulo: non-empty string of 1 to 60 characters.
categoria: "LECTURA", "VIDEO", or "EJERCICIO".
duracionMinutos: integer between 0 and 300.
completado: boolean.
categoriaBuscada: "LECTURA", "VIDEO", or "EJERCICIO".
duracionMaxima: integer between 0 and 300.
Rules
Filtered and transformed recommendations: use filter() to select resources with categoria === categoriaBuscada, completado === false, and duracionMinutos <= duracionMaxima. Then use map() to transform each selected resource into a new object with exactly three properties: id, titulo, and duracionMinutos, preserving the original order.
First pending resource in category: use find() to locate the first resource with categoria === categoriaBuscada and completado === falsewithout filtering by duration. Return its id or null if none exists.
Long pending resources: use some() to check whether there is any pending resource (completado === false) of any category with duracionMinutos > duracionMaxima.
All completed: use every() to check whether all resources have completado === true, while also requiring recursos.length > 0 (if the array is empty, it must be false).
Total pending: count how many resources across the entire catalog have completado === false.
Immutability: do not modify the recursos array or its original objects.
Return Value
Return an object with exactly these six properties:
recomendaciones: array of { id, titulo, duracionMinutos } objects.
totalRecomendaciones: integer with recomendaciones.length.
primerPendienteCategoria: integer with the found id or null.