From d80e63ce4658c1f7b12dbccfd41fe7fd4590146f Mon Sep 17 00:00:00 2001 From: Arkerthan <arkerthan@gmail.com> Date: Tue, 18 Feb 2020 13:27:08 +0100 Subject: [PATCH] simplify assembleList() --- js/utils.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/js/utils.js b/js/utils.js index 57cccf16edd..3feab251a49 100644 --- a/js/utils.js +++ b/js/utils.js @@ -159,17 +159,15 @@ function addA(word) { * @returns {string} */ function assembleList(items) { - switch (items.length) { - case 0: - return "none"; - case 1: - return items[0]; - case 2: - return `${items[0]} and ${items[1]}`; + if (items.length === 0) { + return "none"; + } else if (items.length === 1) { + return items[0]; + } else { + const last = items.pop(); + let r = items.join(", "); + return `${r} and ${last}`; } - const last = items.pop(); - let r = items.join(", "); - return `${r} and ${last}`; } /** -- GitLab