Your Mission
Nexo is designing the Código con Criterio student profile and progress system. Each profile contains a nested configuracion object and a proyectos array, so a shallow copy of the root object alone is not enough to prevent accidental mutations.
Implement the solve(input) function, which receives an object with:
perfil:
id: integer between 1 and 10000.
nombre: non-empty string of 1 to 40 characters.
configuracion: object with tema ("CLARO" or "OSCURO"), notificaciones (boolean), and idioma ("ES" or "EN").
proyectos: array of 0 to 20 objects with id (unique integer between 1 and 1000), nombre (string of 1 to 60 characters), and completado (boolean).
actualizacion:
nuevoNombre: non-empty string of 1 to 40 characters.
nuevoTema: "CLARO" or "OSCURO".
idProyecto: integer between 1 and 1000 (may not exist in proyectos).
marcarCompletado: boolean.
Rules
- Immutability at every level:
- Create a new
perfilActualizado object via spread (...) updating nombre: nuevoNombre.
- Create an independent copy of
configuracion via spread changing only tema: nuevoTema while preserving notificaciones and idioma.
- Create a new
proyectos array via map(), preserving order and length. When proyecto.id === idProyecto, return a new copy of that project with completado: marcarCompletado; for all other projects, preserve their data without mutating any original object.
- Effective change metrics:
nombreModificado: true if perfil.nombre !== nuevoNombre.
temaModificado: true if perfil.configuracion.tema !== nuevoTema.
proyectoEncontrado: true if a project with id === idProyecto exists.
proyectoModificado: true only if the project exists and its original completado value differed from marcarCompletado.
totalCambios: count of actual changes between 0 and 3 (nombreModificado, temaModificado, and proyectoModificado).
totalProyectos: total number of projects in perfilActualizado.proyectos.
Return Value
Return an object with exactly these seven properties:
perfilActualizado
nombreModificado
temaModificado
proyectoEncontrado
proyectoModificado
totalCambios
totalProyectos
Example 1
Input
{
"perfil": {
"id": 10,
"nombre": "Valeria",
"proyectos": [
{
"id": 1,
"nombre": "Landing Page",
"completado": true
},
{
"id": 2,
"nombre": "API REST",
"completado": false
}
],
"configuracion": {
"tema": "CLARO",
"idioma": "ES",
"notificaciones": true
}
},
"actualizacion": {
"nuevoTema": "OSCURO",
"idProyecto": 2,
"nuevoNombre": "Valeria Gómez",
"marcarCompletado": true
}
}Expected result
{
"totalCambios": 3,
"temaModificado": true,
"totalProyectos": 2,
"nombreModificado": true,
"perfilActualizado": {
"id": 10,
"nombre": "Valeria Gómez",
"proyectos": [
{
"id": 1,
"nombre": "Landing Page",
"completado": true
},
{
"id": 2,
"nombre": "API REST",
"completado": true
}
],
"configuracion": {
"tema": "OSCURO",
"idioma": "ES",
"notificaciones": true
}
},
"proyectoEncontrado": true,
"proyectoModificado": true
}Example 2
Input
{
"perfil": {
"id": 25,
"nombre": "Bruno",
"proyectos": [
{
"id": 5,
"nombre": "CLI en Node",
"completado": true
}
],
"configuracion": {
"tema": "OSCURO",
"idioma": "EN",
"notificaciones": false
}
},
"actualizacion": {
"nuevoTema": "OSCURO",
"idProyecto": 5,
"nuevoNombre": "Bruno",
"marcarCompletado": true
}
}Expected result
{
"totalCambios": 0,
"temaModificado": false,
"totalProyectos": 1,
"nombreModificado": false,
"perfilActualizado": {
"id": 25,
"nombre": "Bruno",
"proyectos": [
{
"id": 5,
"nombre": "CLI en Node",
"completado": true
}
],
"configuracion": {
"tema": "OSCURO",
"idioma": "EN",
"notificaciones": false
}
},
"proyectoEncontrado": true,
"proyectoModificado": false
}