Nexo is developing the Código con Criterio academic record manager to update specific fields of a student's file without modifying the original record.
Implement the solve(input) function, which receives an object with:
estudiante: object with exactly five properties in this order:
id: integer between 1 and 10000.
nombre: non-empty string of 1 to 40 characters.
edad: integer between 5 and 100.
curso: non-empty string of 1 to 60 characters.
activo: boolean.
campoActualizar: strictly "nombre", "edad", "curso", or "activo".
nuevoValor: valid new value for the property specified by campoActualizar.
Rules
Destructuring and dynamic lookup: obtain the original id, nombre, and curso by destructuring estudiante. Check with Object.hasOwn(estudiante, campoActualizar) that the property exists and read estudiante[campoActualizar] to obtain valorAnterior.
Immutable update with spread: create a new estudianteActualizado object using the spread operator (...) and a computed property key [campoActualizar]: nuevoValor, preserving all other properties without mutating input.estudiante. The id is never updated.
Change detection and keys: read valorNuevo from estudianteActualizado[campoActualizar], compute huboCambio using strict inequality valorAnterior !== valorNuevo, and get the list of property keys via Object.keys(estudianteActualizado).
Return Value
Return an object with exactly these seven properties:
id: integer with the student's id.
campoActualizado: string with the field name received in campoActualizar.
valorAnterior: original value of that field before the update.
valorNuevo: value of that field after the update.
huboCambio: boolean (true if valorAnterior !== valorNuevo, false otherwise).
campos: array of strings returned by Object.keys(estudianteActualizado).
estudianteActualizado: new object with the updated student data.