In JavaScript, we use const for values that do not change once computed and let when a variable needs to update its value as a process unfolds.
In input, you receive an object describing the inventory movement of a store product:
producto: product name (non-empty string of 1 to 40 characters).
stockInicial: units in stock at the start of the day (0 to 1000).
unidadesRecibidas: new units received today (0 to 1000).
unidadesVendidas: units sold during the day (0 up to stockInicial + unidadesRecibidas).
precioUnitario: selling price per unit in whole pesos (0 to 100000).
Model the inventory evolution step by step:
Initialize an inventory variable with stockInicial and update it by adding unidadesRecibidas to obtain stockDisponible before any sales.
Update the inventory by subtracting unidadesVendidas to obtain stockFinal.
Calculate totalVenta by multiplying unidadesVendidas * precioUnitario.
Return an object with exactly four properties:
producto: the original product name unchanged.
stockDisponible: stock available after receiving merchandise and before selling (stockInicial + unidadesRecibidas).
stockFinal: remaining stock after the sale (stockDisponible - unidadesVendidas).
totalVenta: revenue earned from the sold units (unidadesVendidas * precioUnitario).
Rules and constraints
Always valid inputs: all numbers are integers within the stated ranges, and sold units never exceed available stock (stockFinal >= 0).
Distinguish states: do not confuse stockDisponible (before selling) with stockFinal (after selling).
Allowed tools: use let, const, descriptive variable names, basic arithmetic operations (+, -, *), and return. Do not use conditionals, loops, array methods, classes, 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.