JSFiddle - React, Tailwind, and code Playground

by brigand

JavaScript

const coins = [
  ['$', 100],
  ['q', 25],
  ['d', 10],
  ['n', 5],
  ['p', 1]
];
const r = {}
let cents = Math.round(19.99 * 100);

for (const [symbol, value] of coins) {
  let count = 0;
  while (cents >= value) {
    cents -= value
    count += 1
  }

  r[symbol] = count
}

console.log(r)