Example 1
Input
{
"ventas": [
2000,
4500,
2000
],
"metaDiaria": 8000
}Expected result
{
"ventaMayor": 4500,
"faltanteMeta": 0,
"metaCumplida": true,
"promedioVenta": 2833,
"cantidadVentas": 3,
"totalRecaudado": 8500
}Nexo is preparing the challenges…
Nexo · Connect the ideas
Traverse sales from Nexo's tech store with a for or while loop to compute total revenue, integer average, largest sale, and daily goal progress.
bucles · acumuladores · arrays
At the tech store managed by Nexo, at the end of each shift you need to generate the cash register summary: iterate through all transactions recorded during the day, accumulate total revenue, identify the largest sale, and check whether the daily goal was reached.
Implement the solve(input) function, which receives a JSON object with two properties:
ventas: array of 0 to 100 integers, where each element represents a sale between 0 and 100000 cents.metaDiaria: integer between 0 and 10000000 cents.Calculation rules:
ventas (including 0-cent sales, which still count as recorded transactions).totalRecaudado: sum of all amounts in ventas (0 if ventas is empty).cantidadVentas: total number of records in ventas (0 if empty).promedioVenta: integer average calculated as Math.floor(totalRecaudado / cantidadVentas), or 0 when ventas is empty.ventaMayor: the maximum amount found in ventas, or 0 when ventas is empty.metaCumplida: boolean true when totalRecaudado >= metaDiaria.faltanteMeta: how many cents are still needed to reach metaDiaria (metaDiaria - totalRecaudado), or 0 if the goal was already met or exceeded.Return a JSON object with those exact six properties: totalRecaudado, cantidadVentas, promedioVenta, ventaMayor, metaCumplida, and faltanteMeta.
for or while loop to sum sales and find the maximum.length, index access, if, and Math.floor() is allowed.reduce(), map(), filter(), sort(), Math.max(...ventas), recursion, classes, or helper functions.Input
{
"ventas": [
2000,
4500,
2000
],
"metaDiaria": 8000
}Expected result
{
"ventaMayor": 4500,
"faltanteMeta": 0,
"metaCumplida": true,
"promedioVenta": 2833,
"cantidadVentas": 3,
"totalRecaudado": 8500
}Input
{
"ventas": [
1500,
0,
3000
],
"metaDiaria": 6000
}Expected result
{
"ventaMayor": 3000,
"faltanteMeta": 1500,
"metaCumplida": false,
"promedioVenta": 1500,
"cantidadVentas": 3,
"totalRecaudado": 4500
}Input
{
"ventas": [],
"metaDiaria": 5000
}Expected result
{
"ventaMayor": 0,
"faltanteMeta": 5000,
"metaCumplida": false,
"promedioVenta": 0,
"cantidadVentas": 0,
"totalRecaudado": 0
}Implement solve(input) and return the result. Synchronous JavaScript, without packages, network or account access.
126/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.