From d39a74930ec054628f8c65d33ef797fdea6f44ce Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 11 Nov 2023 21:23:38 -0600 Subject: add create_world() --- src/util.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/util.js') 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)); + } +} -- cgit v1.2.1