{ "data": [ { "id": "all", "title": "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.prototype.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.\n\n", "codeBlocks": { "es6": "const all = (arr, fn = Boolean) => arr.every(fn);", "es5": "var all = function all(arr) {\n var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Boolean;\n return arr.every(fn);\n};", "example": "all([4, 2, 3], x => x > 1); // true\nall([1, 2, 3]); // true" }, "tags": [ "array", "function", "beginner" ] }, "meta": { "hash": "ba8e5f17500d1e5428f4ca7fcc8095934a7ad3aa496b35465e8f7799f1715aaa", "firstSeen": "1518601575", "lastUpdated": "1565681352", "updateCount": 6, "authorCount": 4 } }, { "id": "allEqual", "title": "allEqual", "type": "snippet", "attributes": { "fileName": "allEqual.md", "text": "Check if all elements in an array are equal.\n\nUse `Array.prototype.every()` to check if all the elements of the array are the same as the first one.\nElements in the array are compared using the strict comparison operator, which does not account for `NaN` self-inequality.\n\n", "codeBlocks": { "es6": "const allEqual = arr => arr.every(val => val === arr[0]);", "es5": "var allEqual = function allEqual(arr) {\n return arr.every(function (val) {\n return val === arr[0];\n });\n};", "example": "allEqual([1, 2, 3, 4, 5, 6]); // false\nallEqual([1, 1, 1, 1]); // true" }, "tags": [ "array", "function", "beginner" ] }, "meta": { "hash": "bda519858588ad61c9200acbb4ea5ce66630eb2ed7ceda96d12518b772b986b9", "firstSeen": "1533243788", "lastUpdated": "1565681352", "updateCount": 6, "authorCount": 4 } }, { "id": "any", "title": "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.prototype.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.\n\n", "codeBlocks": { "es6": "const any = (arr, fn = Boolean) => arr.some(fn);", "es5": "var any = function any(arr) {\n var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Boolean;\n return arr.some(fn);\n};", "example": "any([0, 1, 2, 0], x => x >= 2); // true\nany([0, 0, 1, 0]); // true" }, "tags": [ "array", "function", "beginner" ] }, "meta": { "hash": "061b791456507197b9be0ff9b791b830fe0b550823868075bbe04962501f83a3", "firstSeen": "1518601575", "lastUpdated": "1565681352", "updateCount": 6, "authorCount": 4 } }, { "id": "approximatelyEqual", "title": "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`.\n\n", "codeBlocks": { "es6": "const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;", "es5": "var approximatelyEqual = function approximatelyEqual(v1, v2) {\n var epsilon = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.001;\n return Math.abs(v1 - v2) < epsilon;\n};", "example": "approximatelyEqual(Math.PI / 2.0, 1.5708); // true" }, "tags": [ "math", "beginner" ] }, "meta": { "hash": "805f11e2f230c3a6b7dc590fcee27b4083b2188b6f1d0a8afb93868891cdba22", "firstSeen": "1518605233", "lastUpdated": "1565681352", "updateCount": 4, "authorCount": 3 } }, { "id": "arrayToCSV", "title": "arrayToCSV", "type": "snippet", "attributes": { "fileName": "arrayToCSV.md", "text": "Converts a 2D array to a comma-separated values (CSV) string.\n\nUse `Array.prototype.map()` and `Array.prototype.join(delimiter)` to combine individual 1D arrays (rows) into strings.\nUse `Array.prototype.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 `,`.\n\n", "codeBlocks": { "es6": "const arrayToCSV = (arr, delimiter = ',') =>\n arr\n .map(v => v.map(x => (isNaN(x) ? `\"${x.replace(/\"/g, '\"\"')}\"` : x)).join(delimiter))\n .join('\\n');", "es5": "var arrayToCSV = function arrayToCSV(arr) {\n var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';\n return arr.map(function (v) {\n return v.map(function (x) {\n return isNaN(x) ? \"\\\"\".concat(x.replace(/\"/g, '\"\"'), \"\\\"\") : x;\n }).join(delimiter);\n }).join('\\n');\n};", "example": "arrayToCSV([['a', 'b'], ['c', 'd']]); // '\"a\",\"b\"\\n\"c\",\"d\"'\narrayToCSV([['a', 'b'], ['c', 'd']], ';'); // '\"a\";\"b\"\\n\"c\";\"d\"'\narrayToCSV([['a', '\"b\" great'], ['c', 3.1415]]); // '\"a\",\"\"\"b\"\" great\"\\n\"c\",3.1415'" }, "tags": [ "array", "string", "utility", "intermediate" ] }, "meta": { "hash": "aeabb3d1d2be2d44fd8a20da3b069fdd1a8ad963f27e3e1ae9f5e8b40a8908cb", "firstSeen": "1530120403", "lastUpdated": "1565681352", "updateCount": 11, "authorCount": 5 } }, { "id": "arrayToHtmlList", "title": "arrayToHtmlList", "type": "snippet", "attributes": { "fileName": "arrayToHtmlList.md", "text": "Converts the given array elements into `