loading...

re: Daily Challenge #144 - Box Office Clerk VIEW POST

FULL DISCUSSION
 

Another JS approach

const tickets = bills => {
  let status = "YES";

  const register = bills.reduce(
    (acc, val) => {
      acc[val] += 1;
      return acc;
    },
    { 25: 0, 50: 0, 100: 0 }
  );

  const removeFromRegister = bills =>
    bills.forEach(bill => (register[bill] -= 1));

  bills.forEach(bill => {
    if (bill === 100) removeFromRegister([50, 25]);
    if (bill === 50) removeFromRegister([25]);
  });

  Object.values(register).forEach(item => {
    if (item < 0) status = "NO";
  });

  return status;
};

console.log(tickets([25, 25, 50, 50, 100])); //NO

CondeSandbox

code of conduct - report abuse