My current JavaScript list consists of dollar coin values:
let x = [1.0, 2.5, 5.0, 20.0, 50.0, 100.0, 500.0, 2000.0, 5000.0]
My challenge is finding an equation in JavaScript that will allow me to use the smallest number of coins to reach the desired maximum value.
For instance, if I want to max out at 5.5 USD, I would need to use a 2.5 USD coin and three 1.0 USD coins to total 5.5 USD.
One important rule is that the total value must not exceed the desired amount.
Does anyone know of a specific mathematical function or equation type that can help me with this task?