From f9fc4d26ec5fca9ee175c8a6fbcdd0fa36f10947 Mon Sep 17 00:00:00 2001 From: sanine Date: Thu, 16 Nov 2023 14:50:00 -0600 Subject: clear out js files --- src/util.js | 62 ------------------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/util.js (limited to 'src/util.js') diff --git a/src/util.js b/src/util.js deleted file mode 100644 index f83039f..0000000 --- a/src/util.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - - -export function create(obj, proto=Object.prototype) { - const props = Object.keys(obj) - .map((key) => [ key, { value: obj[key], enumerable: true } ]) - .reduce((acc, [ key, value ]) => ({ ...acc, [key]: value }), {}); - - return Object.create(proto, props); -}; - - -export function random_choice(collection, r=Math.random()) { - const idx = Math.floor(collection.length * r); - return collection[idx]; -} - - -export function pairs(arr1, arr2) { - return arr1 - .map((x, i) => arr2.map(y => [x, y])) - .flat(); -} - - -export function deepEqual(a, b, debug=false) { - if (typeof(a) === 'object') { - if (typeof(b) === 'object') { - // do deep equality - return [...new Set(Object.keys(a).concat(Object.keys(b)))].reduce( - (acc, key) => { - return acc && deepEqual(a[key], b[key]); - }, - true - ); - } else { - // one object, one non-object - return false; - } - } else { - return a === b; - } -} - - -export function apply(f, n, x0) { - if (n == 0) { - return x0; - } else { - return f(apply(f, n-1, x0)); - } -} - - -export function shuffle(arr) { - const shuffled = [...arr]; - for (let i=arr.length-1; i > 0; i--) { - const j = Math.floor(Math.random() * (i+1)); - [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]] - } - return shuffled; -} -- cgit v1.2.1