diff options
Diffstat (limited to 'src/util.js')
-rw-r--r-- | src/util.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/util.js b/src/util.js index 74233f4..ecae45e 100644 --- a/src/util.js +++ b/src/util.js @@ -10,7 +10,7 @@ export function create(obj, proto=Object.prototype) { };
-export function random_choice(collection, r) {
+export function random_choice(collection, r=Math.random()) {
const idx = Math.floor(collection.length * r);
return collection[idx];
}
@@ -41,3 +41,12 @@ export function deepEqual(a, b, debug=false) { return a === b;
}
}
+
+
+export function apply(f, n, x0) {
+ if (n == 0) {
+ return x0;
+ } else {
+ return f(apply(f, n-1, x0));
+ }
+}
|