diff --git a/js/utils.js b/js/utils.js index daf43d3fd156d5a604476dad1ef21cb2a887ed7b..e888c603445f2080af61eda4b26cfef7b7ead911 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}