diff options
author | sanine <sanine.not@pm.me> | 2023-11-11 21:23:38 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-11 21:23:38 -0600 |
commit | d39a74930ec054628f8c65d33ef797fdea6f44ce (patch) | |
tree | 0eda8f851410c4c1bfe57755b59a69bf332fd237 /src/util.js | |
parent | 4715baef25b39d2614b1d0cc67d8bcff5676b6ce (diff) |
add create_world()
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));
+ }
+}
|