Spreadsheet: Add a 'choose' function
This commit is contained in:
parent
f159d161fa
commit
9c1143fe13
Notes:
sideshowbarker
2024-07-19 02:08:35 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/9c1143fe134 Pull-request: https://github.com/SerenityOS/serenity/pull/3621 Reviewed-by: https://github.com/linusg
1 changed files with 19 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue