From 9df7b637ec448eaee7738f1ca3c7e99a3bce3bd8 Mon Sep 17 00:00:00 2001 From: Floris Bartra Date: Wed, 4 Dec 2024 15:11:21 +0100 Subject: [PATCH] Factorise pizza count --- src/views/AdminPizza/AdminPizza.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/views/AdminPizza/AdminPizza.vue b/src/views/AdminPizza/AdminPizza.vue index f0fe090..d65f76f 100644 --- a/src/views/AdminPizza/AdminPizza.vue +++ b/src/views/AdminPizza/AdminPizza.vue @@ -276,6 +276,24 @@ const handleWheel = (event: WheelEvent) => { const target = event.target as HTMLInputElement; target.blur(); }; + +const factorise = (pizzas: number[]) => { + const counts: Record = {}; + pizzas.forEach((pizza) => { + if (counts[pizza] === undefined) { + counts[pizza] = 1; + } else { + counts[pizza] += 1; + } + }); + return Object.keys(counts).map((pizza) => { + const pizzaId = parseInt(pizza, 10); + if (counts[pizzaId] > 1) { + return `${pizzaList.value[pizzaId].name} x${counts[pizzaId]}`; + } + return pizzaList.value[pizzaId].name; + }).join(', '); +};