Spreadsheet: Add a 'choose' function

This commit is contained in:
AnotherTest 2020-09-26 16:18:06 +03:30 committed by Andreas Kling
parent f159d161fa
commit 9c1143fe13
Notes: sideshowbarker 2024-07-19 02:08:35 +09:00

View file

@ -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,