diff --git a/Base/res/js/Spreadsheet/runtime.js b/Base/res/js/Spreadsheet/runtime.js index 67e66307e0..75d8da26ba 100644 --- a/Base/res/js/Spreadsheet/runtime.js +++ b/Base/res/js/Spreadsheet/runtime.js @@ -128,6 +128,12 @@ function select(criteria, t, f) { return f; } +function choose(index, ...args) { + if (index > args.length) return undefined; + if (index < 0) return undefined; + return args[index]; +} + function now() { return new Date(); } @@ -299,6 +305,19 @@ select.__documentation = JSON.stringify({ }, }); +choose.__documentation = JSON.stringify({ + name: "choose", + argc: 1, + argnames: ["index"], + doc: "Selects an argument by the given `index`, starting at zero", + examples: { + "choose(A3, 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')": + "Get the day name by the number in A3", + "choose(randRange(0, 2), 'Well', 'Hello', 'Friends')": + "Randomly pick one of the three words 'well', 'hello' and 'friends'", + }, +}); + now.__documentation = JSON.stringify({ name: "now", argc: 0,