Middle
// [phone] function getMoney(amount) { // Твой код здесь } console.log(getMoney(4650));
sobes.tech AI
Answer from AI
The task is most likely to break down a sum into bills or coins. For example, if we consider denominations of 1000, 500, 100, 50, 10, 5, 1, we need to determine how many and which bills/coins are required to make up the sum.
Here's an example solution in JavaScript:
function getMoney(amount) {
const denominations = [1000, 500, 100, 50, 10, 5, 1];
const result = {};
for (const denom of denominations) {
const count = Math.floor(amount / denom);
if (count > 0) {
result[denom] = count;
amount -= denom * count;
}
}
return result;
}
console.log(getMoney(4650));
// Output: { '1000': 4, '500': 1, '100': 1, '50': 1 }
This is a classic greedy algorithm for money change.