Example 1
Input
{
"edad": 11,
"edadMaxima": 60,
"edadMinima": 12,
"tieneAutorizacion": true
}Expected result
{
"estado": "RECHAZADO_EDAD_MINIMA",
"dentroDelRango": false,
"puedeParticipar": false,
"requiereAutorizacion": false
}Nexo is preparing the challenges…
Nexo · Connect the ideas
Determine whether a person can participate in an activity by evaluating age ranges, boundary values, and authorization using if, else if, and else.
condicionales · comparaciones · valores-limite
When programming admission rules, the priority order of conditions and careful handling of boundary values (inclusive vs. exclusive) determine whether a system makes consistent decisions. For example, a special authorization intended for people above the upper age limit should never qualify someone who does not even meet the minimum age.
Implement the solve(input) function, which receives a JSON object with four properties:
edad: integer between 0 and 120.edadMinima: integer between 1 and 100.edadMaxima: integer between edadMinima and 120.tieneAutorizacion: boolean.Evaluate the following rules in priority order using conditional structures (if, else if, else):
edad is less than edadMinima, the person is always rejected, even if tieneAutorizacion is true. Status: "RECHAZADO_EDAD_MINIMA".edad is between edadMinima and edadMaxima (both inclusive), the person is accepted without needing authorization. Status: "ACEPTADO".edad is greater than edadMaxima and tieneAutorizacion is true, the person is accepted. Status: "ACEPTADO_CON_AUTORIZACION".edad is greater than edadMaxima and tieneAutorizacion is false, the person is rejected. Status: "RECHAZADO_SIN_AUTORIZACION".Return a JSON object with those exact four properties:
puedeParticipar: boolean (true if accepted, false if rejected).estado: string with one of the four status values above.requiereAutorizacion: boolean that is true only when edad > edadMaxima (regardless of whether the person has authorization).dentroDelRango: boolean that is true when edad >= edadMinima && edad <= edadMaxima.if, else if, else); do not solve everything with chained ternary operators.[edadMinima, edadMaxima] range, their status is "ACEPTADO" even if tieneAutorizacion is true.Input
{
"edad": 11,
"edadMaxima": 60,
"edadMinima": 12,
"tieneAutorizacion": true
}Expected result
{
"estado": "RECHAZADO_EDAD_MINIMA",
"dentroDelRango": false,
"puedeParticipar": false,
"requiereAutorizacion": false
}Input
{
"edad": 25,
"edadMaxima": 65,
"edadMinima": 18,
"tieneAutorizacion": false
}Expected result
{
"estado": "ACEPTADO",
"dentroDelRango": true,
"puedeParticipar": true,
"requiereAutorizacion": false
}Input
{
"edad": 70,
"edadMaxima": 65,
"edadMinima": 18,
"tieneAutorizacion": true
}Expected result
{
"estado": "ACEPTADO_CON_AUTORIZACION",
"dentroDelRango": false,
"puedeParticipar": true,
"requiereAutorizacion": true
}Implement solve(input) and return the result. Synchronous JavaScript, without packages, network or account access.
120/10.000 characters · In the advanced editor, press Escape and then Tab to leave.
Your code is restored in this browser. Saving to your account is optional.
Try solving it first. Viewing the solution records assisted use.