{ "data": [ { "id": "all", "type": "snippet", "attributes": { "fileName": "all.md", "text": "Returns `true` if the provided predicate function returns `true` for all elements in a collection, `false` otherwise.\n\nUse `Array.every()` to test if all elements in the collection return `true` based on `fn`.\nOmit the second argument, `fn`, to use `Boolean` as a default.", "codeBlocks": [ "const all = (arr, fn = Boolean) => arr.every(fn);", "all([4, 2, 3], x => x > 1); // true\nall([1, 2, 3]); // true" ], "tags": [ "array", "function" ] }, "meta": { "archived": false, "hash": "8a036b5ffee127e5456d59e36f3c9abb24f1692f6a398b61c20ebacaae8380e4" } }, { "id": "any", "type": "snippet", "attributes": { "fileName": "any.md", "text": "Returns `true` if the provided predicate function returns `true` for at least one element in a collection, `false` otherwise.\n\nUse `Array.some()` to test if any elements in the collection return `true` based on `fn`.\nOmit the second argument, `fn`, to use `Boolean` as a default.", "codeBlocks": [ "const any = (arr, fn = Boolean) => arr.some(fn);", "any([0, 1, 2, 0], x => x >= 2); // true\nany([0, 0, 1, 0]); // true" ], "tags": [ "array", "function" ] }, "meta": { "archived": false, "hash": "15bee4484e96a2d052368ef9dd743819b30d8d883b52575bee65fdc194dc9e93" } }, { "id": "approximatelyEqual", "type": "snippet", "attributes": { "fileName": "approximatelyEqual.md", "text": "Checks if two numbers are approximately equal to each other.\n\nUse `Math.abs()` to compare the absolute difference of the two values to `epsilon`.\nOmit the third parameter, `epsilon`, to use a default value of `0.001`.", "codeBlocks": [ "const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;", "approximatelyEqual(Math.PI / 2.0, 1.5708); // true" ], "tags": [ "math" ] }, "meta": { "archived": false, "hash": "4fa8b87ac30ec67afe40c80101a702986dd1e5cab3cd8b9653f1b7c8cbac7540" } }, { "id": "arrayToCSV", "type": "snippet", "attributes": { "fileName": "arrayToCSV.md", "text": "Converts a 2D array to a comma-separated values (CSV) string.\n\nUse `Array.map()` and `Array.join(delimiter)` to combine individual 1D arrays (rows) into strings.\nUse `Array.join('\\n')` to combine all rows into a CSV string, separating each row with a newline.\nOmit the second argument, `delimiter`, to use a default delimiter of `,`.", "codeBlocks": [ "const arrayToCSV = (arr, delimiter = ',') =>\n arr.map(v => v.map(x => `\"${x}\"`).join(delimiter)).join('\\n');", "arrayToCSV([['a', 'b'], ['c', 'd']]); // '\"a\",\"b\"\\n\"c\",\"d\"'\narrayToCSV([['a', 'b'], ['c', 'd']], ';'); // '\"a\";\"b\"\\n\"c\";\"d\"'" ], "tags": [ "array", "string", "utility" ] }, "meta": { "archived": false, "hash": "47f27df615f87cf59e53ae3a618249f8413dd9d9c8939296a8b8f3785697de3d" } }, { "id": "arrayToHtmlList", "type": "snippet", "attributes": { "fileName": "arrayToHtmlList.md", "text": "Converts the given array elements into `