Open this example in the interactive library
Source code
const packs = [
{ n: 6, cents: 600 },
{ n: 10, cents: 950 },
];
console.log(packs.toSorted((a, b) => a.cents / a.n - b.cents / b.n)[0]);
Sample output
{ n: 10, cents: 950 }
Open this example in the interactive library
const packs = [
{ n: 6, cents: 600 },
{ n: 10, cents: 950 },
];
console.log(packs.toSorted((a, b) => a.cents / a.n - b.cents / b.n)[0]);
{ n: 10, cents: 950 }