curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69738771fb5a7b8b24cca2a5.md
Given an array of integers representing the coins in your pocket, with each integer being the value of a coin in cents, return the total amount in the format "$D.CC".
countChange([25, 10, 5, 1]) should return "$0.41".
assert.equal(countChange([25, 10, 5, 1]), "$0.41");
countChange([25, 10, 5, 1, 25, 10, 25, 1, 1, 10, 5, 25]) should return "$1.43".
assert.equal(countChange([25, 10, 5, 1, 25, 10, 25, 1, 1, 10, 5, 25]), "$1.43");
countChange([100, 25, 100, 1000, 5, 500, 2000, 25]) should return "$37.55".
assert.equal(countChange([100, 25, 100, 1000, 5, 500, 2000, 25]), "$37.55");
countChange([10, 5, 1, 10, 1, 25, 1, 1, 5, 1, 10]) should return "$0.70".
assert.equal(countChange([10, 5, 1, 10, 1, 25, 1, 1, 5, 1, 10]), "$0.70");
countChange([1]) should return "$0.01".
assert.equal(countChange([1]), "$0.01");
countChange([25, 25, 25, 25]) should return "$1.00".
assert.equal(countChange([25, 25, 25, 25]), "$1.00");
function countChange(change) {
return change;
}
function countChange(change) {
const totalCents = change.reduce((sum, coin) => sum + coin, 0);
const dollars = Math.floor(totalCents / 100);
const cents = totalCents % 100;
return `$${dollars}.${cents.toString().padStart(2, "0")}`;
}