From d07e95b998a242b6f16aede74f3870e72fffab3e Mon Sep 17 00:00:00 2001 From: Arkerthan <arkerthan@gmail.com> Date: Mon, 17 Feb 2020 23:28:09 +0100 Subject: [PATCH] add assembleList(items) --- js/utils.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/utils.js b/js/utils.js index daf43d3fd15..e888c603445 100644 --- a/js/utils.js +++ b/js/utils.js @@ -152,6 +152,26 @@ function addA(word) { return `a ${word}`; } +/** + * Assembles a list of strings into a proper list. + * + * @param {Array<string>} items + * @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]}`; + } + const last = items.pop(); + let r = items.join(", "); + return `${r} and ${last}`; +} + /** * @param {number} i * @returns {string} -- GitLab