Your mission
When a calculation has multiple stages, it helps to store intermediate results before combining them into the final answer. That way, each step depends on clear, verifiable data.
In input, you receive an object with the productos property, which holds an array of exactly three objects. Each item represents a product and has two properties:
precio: unit price in whole pesos (0 to 1000).
cantidad: units purchased (0 to 1000).
Solve the problem sequentially:
- Directly access the three products using their known positions (
input.productos[0], input.productos[1], and input.productos[2]) and calculate each subtotal by multiplying precio * cantidad.
- Calculate
total by adding the three subtotals obtained in the previous step.
- Return an object with exactly two properties:
subtotales: an array of the three integer subtotals in the same order received.
total: an integer representing the sum of the three subtotals.
Rules and constraints
- Input types and bounds:
input.productos always has length 3, and both precio and cantidad are integers between 0 and 1000 (inclusive), with no decimals or discounts.
- Output order and shape: preserve the original order of the three products in
subtotales and always return the object { subtotales, total } using return.
- Allowed tools: access elements directly by index (
[0], [1], [2]), and use variables and basic arithmetic operations (* and +). Do not use loops, array methods (map, reduce, forEach), conditionals, helper functions, or console.log as output.
Contract
Complete function solve(input) and return the resulting object. The input always satisfies the described constraints. Do not use network calls, files, imports, packages, or asynchronous code.