summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-09-26 16:18:06 +0330
committerAndreas Kling <kling@serenityos.org>2020-09-28 17:41:48 +0200
commit9c1143fe1348b9309d288808fa3304fdc1b9f785 (patch)
treed2afce8a22f6a6524b3052d22ac39b71531e63ae
parentf159d161fa6c15aa16cdac6967a2b165d0f9fef0 (diff)
downloadserenity-9c1143fe1348b9309d288808fa3304fdc1b9f785.zip
Spreadsheet: Add a 'choose' function
-rw-r--r--Base/res/js/Spreadsheet/runtime.js19
1 files changed, 19 insertions, 0 deletions
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,