{ "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.\r\n\r\nUse `Array.prototype.every()` to test if all elements in the collection return `true` based on `fn`.\r\nOmit the second argument, `fn`, to use `Boolean` as a default.", "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\r\nall([1, 2, 3]); // true" }, "tags": [ "array", "function", "beginner" ] }, "meta": { "archived": false, "hash": "d9aec5efedaa39586f2b1210394b345cb1abbb9348fad952e785badbb2d598ac" } }, { "id": "allEqual", "type": "snippet", "attributes": { "fileName": "allEqual.md", "text": "Check if all elements in an array are equal.\r\n\r\nUse `Array.prototype.every()` to check if all the elements of the array are the same as the first one.", "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\r\nallEqual([1, 1, 1, 1]); // true" }, "tags": [ "array", "function", "beginner" ] }, "meta": { "archived": false, "hash": "76704202f5987a78625746ef4f2ca5650a8d87b10252b06b60c5d39cd26a7335" } }, { "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.\r\n\r\nUse `Array.prototype.some()` to test if any elements in the collection return `true` based on `fn`.\r\nOmit the second argument, `fn`, to use `Boolean` as a default.", "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\r\nany([0, 0, 1, 0]); // true" }, "tags": [ "array", "function", "beginner" ] }, "meta": { "archived": false, "hash": "b34cb378a31ae73335f941448fe873edf9c06e10d5a1e28895275a29dd471c39" } }, { "id": "approximatelyEqual", "type": "snippet", "attributes": { "fileName": "approximatelyEqual.md", "text": "Checks if two numbers are approximately equal to each other.\r\n\r\nUse `Math.abs()` to compare the absolute difference of the two values to `epsilon`.\r\nOmit the third parameter, `epsilon`, to use a default value of `0.001`.", "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": { "archived": false, "hash": "2b68e79d3ebb806379c3b84ae70152e033297d6e4fd4bc779b10be81ca2fc0cf" } }, { "id": "arrayToCSV", "type": "snippet", "attributes": { "fileName": "arrayToCSV.md", "text": "Converts a 2D array to a comma-separated values (CSV) string.\r\n\r\nUse `Array.prototype.map()` and `Array.prototype.join(delimiter)` to combine individual 1D arrays (rows) into strings.\r\nUse `Array.prototype.join('\\n')` to combine all rows into a CSV string, separating each row with a newline.\r\nOmit the second argument, `delimiter`, to use a default delimiter of `,`.", "codeBlocks": { "es6": "const arrayToCSV = (arr, delimiter = ',') =>\r\n arr.map(v => v.map(x => `\"${x}\"`).join(delimiter)).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 \"\\\"\".concat(x, \"\\\"\");\n }).join(delimiter);\n }).join('\\n');\n};", "example": "arrayToCSV([['a', 'b'], ['c', 'd']]); // '\"a\",\"b\"\\n\"c\",\"d\"'\r\narrayToCSV([['a', 'b'], ['c', 'd']], ';'); // '\"a\";\"b\"\\n\"c\";\"d\"'" }, "tags": [ "array", "string", "utility", "intermediate" ] }, "meta": { "archived": false, "hash": "0ba7229cc896c4efeb982ea313166afa79aee16cbf337a643243a4f8c3a4bcd9" } }, { "id": "arrayToHtmlList", "type": "snippet", "attributes": { "fileName": "arrayToHtmlList.md", "text": "Converts the given array elements into `