{ "data": [ { "id": "all", "type": "snippetListing", "title": "all", "attributes": { "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", "tags": [ "array", "function", "beginner" ] }, "meta": { "hash": "ba8e5f17500d1e5428f4ca7fcc8095934a7ad3aa496b35465e8f7799f1715aaa" } }, { "id": "allEqual", "type": "snippetListing", "title": "allEqual", "attributes": { "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", "tags": [ "array", "function", "beginner" ] }, "meta": { "hash": "bda519858588ad61c9200acbb4ea5ce66630eb2ed7ceda96d12518b772b986b9" } }, { "id": "any", "type": "snippetListing", "title": "any", "attributes": { "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", "tags": [ "array", "function", "beginner" ] }, "meta": { "hash": "061b791456507197b9be0ff9b791b830fe0b550823868075bbe04962501f83a3" } }, { "id": "approximatelyEqual", "type": "snippetListing", "title": "approximatelyEqual", "attributes": { "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", "tags": [ "math", "beginner" ] }, "meta": { "hash": "805f11e2f230c3a6b7dc590fcee27b4083b2188b6f1d0a8afb93868891cdba22" } }, { "id": "arrayToCSV", "type": "snippetListing", "title": "arrayToCSV", "attributes": { "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", "tags": [ "array", "string", "utility", "intermediate" ] }, "meta": { "hash": "aeabb3d1d2be2d44fd8a20da3b069fdd1a8ad963f27e3e1ae9f5e8b40a8908cb" } }, { "id": "arrayToHtmlList", "type": "snippetListing", "title": "arrayToHtmlList", "attributes": { "text": "Converts the given array elements into `
  • ` tags and appends them to the list of the given id.\n\nUse `Array.prototype.map()`, `document.querySelector()`, and an anonymous inner closure to create a list of html tags.\n\n", "tags": [ "browser", "array", "intermediate" ] }, "meta": { "hash": "9d7e2db4a98688ab199ed2f75242bbff40a6083cc3c0ef483ed679c5d3878239" } }, { "id": "ary", "type": "snippetListing", "title": "ary", "attributes": { "text": "Creates a function that accepts up to `n` arguments, ignoring any additional arguments.\n\nCall the provided function, `fn`, with up to `n` arguments, using `Array.prototype.slice(0,n)` and the spread operator (`...`).\n\n", "tags": [ "adapter", "function", "intermediate" ] }, "meta": { "hash": "918d65f04bafeb3ee0b855a52805773e8a8dc818fec1daa4ad0940dba32de9e8" } }, { "id": "atob", "type": "snippetListing", "title": "atob", "attributes": { "text": "Decodes a string of data which has been encoded using base-64 encoding.\n\nCreate a `Buffer` for the given string with base-64 encoding and use `Buffer.toString('binary')` to return the decoded string.\n\n", "tags": [ "node", "string", "utility", "beginner" ] }, "meta": { "hash": "32988360d63d6d62251314a88d3f4482ec3a265d67154a92a86d4140bd61c54b" } }, { "id": "attempt", "type": "snippetListing", "title": "attempt", "attributes": { "text": "Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.\n\nUse a `try... catch` block to return either the result of the function or an appropriate error.\n\n", "tags": [ "function", "intermediate" ] }, "meta": { "hash": "a511836ad4a5755d469af2e6a331cbcd85df14b6231bbed6a1b0fe44aee3d2cf" } }, { "id": "average", "type": "snippetListing", "title": "average", "attributes": { "text": "Returns the average of two or more numbers.\n\nUse `Array.prototype.reduce()` to add each value to an accumulator, initialized with a value of `0`, divide by the `length` of the array.\n\n", "tags": [ "math", "array", "beginner" ] }, "meta": { "hash": "edf5c7f142e59e4467ca7142eaf0ac95957abcb0dad1d439484b2b70fe8be6d3" } }, { "id": "averageBy", "type": "snippetListing", "title": "averageBy", "attributes": { "text": "Returns the average of an array, after mapping each element to a value using the provided function.\n\nUse `Array.prototype.map()` to map each element to the value returned by `fn`, `Array.prototype.reduce()` to add each value to an accumulator, initialized with a value of `0`, divide by the `length` of the array.\n\n", "tags": [ "math", "array", "function", "intermediate" ] }, "meta": { "hash": "7aa2052a6196029116ef9f2f7dda69b7d17344c0acc659ffedf002024b38d8b7" } }, { "id": "bifurcate", "type": "snippetListing", "title": "bifurcate", "attributes": { "text": "Splits values into two groups. If an element in `filter` is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.\n\nUse `Array.prototype.reduce()` and `Array.prototype.push()` to add elements to groups, based on `filter`.\n\n", "tags": [ "array", "intermediate" ] }, "meta": { "hash": "a801974915906c11a30deef1baa3994f44f548f1ca1cf599aede4bb730543ec6" } }, { "id": "bifurcateBy", "type": "snippetListing", "title": "bifurcateBy", "attributes": { "text": "Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group.\n\nUse `Array.prototype.reduce()` and `Array.prototype.push()` to add elements to groups, based on the value returned by `fn` for each element.\n\n", "tags": [ "array", "function", "intermediate" ] }, "meta": { "hash": "db1b8580ab11b6ba05a7d47776b97d700c5a7e945ddc5ad9ca1f37e50f039b54" } }, { "id": "bind", "type": "snippetListing", "title": "bind", "attributes": { "text": "Creates a function that invokes `fn` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments.\n\nReturn a `function` that uses `Function.prototype.apply()` to apply the given `context` to `fn`.\nUse `Array.prototype.concat()` to prepend any additional supplied parameters to the arguments.\n\n", "tags": [ "function", "object", "intermediate" ] }, "meta": { "hash": "d15851c4e6991e41014768c3f2dd28df71615e44180c732b67eed1d162ea4b95" } }, { "id": "bindAll", "type": "snippetListing", "title": "bindAll", "attributes": { "text": "Binds methods of an object to the object itself, overwriting the existing method.\n\nUse `Array.prototype.forEach()` to return a `function` that uses `Function.prototype.apply()` to apply the given context (`obj`) to `fn` for each function specified.\n\n", "tags": [ "object", "function", "intermediate" ] }, "meta": { "hash": "e159b77ba0bde0f38d339348b9a69b4702cf036abd767777507159aa75ce151b" } }, { "id": "bindKey", "type": "snippetListing", "title": "bindKey", "attributes": { "text": "Creates a function that invokes the method at a given key of an object, optionally adding any additional supplied parameters to the beginning of the arguments.\n\nReturn a `function` that uses `Function.prototype.apply()` to bind `context[fn]` to `context`.\nUse the spread operator (`...`) to prepend any additional supplied parameters to the arguments.\n\n", "tags": [ "function", "object", "intermediate" ] }, "meta": { "hash": "e854f774dd81cdb291fb57b276a61e5d7f7ab13a6aae490c89c0e00acde820b4" } }, { "id": "binomialCoefficient", "type": "snippetListing", "title": "binomialCoefficient", "attributes": { "text": "Evaluates the binomial coefficient of two integers `n` and `k`.\n\nUse `Number.isNaN()` to check if any of the two values is `NaN`.\nCheck if `k` is less than `0`, greater than or equal to `n`, equal to `1` or `n - 1` and return the appropriate result.\nCheck if `n - k` is less than `k` and switch their values accordingly.\nLoop from `2` through `k` and calculate the binomial coefficient.\nUse `Math.round()` to account for rounding errors in the calculation.\n\n", "tags": [ "math", "intermediate" ] }, "meta": { "hash": "0f36f6b8c7f803a55d8e888c8794cacba02db79c4d54043a8ddc71249c2f8a9f" } }, { "id": "bottomVisible", "type": "snippetListing", "title": "bottomVisible", "attributes": { "text": "Returns `true` if the bottom of the page is visible, `false` otherwise.\n\nUse `scrollY`, `scrollHeight` and `clientHeight` to determine if the bottom of the page is visible.\n\n", "tags": [ "browser", "intermediate" ] }, "meta": { "hash": "9c2b4a28ae4f39cc034dc75e98d2f405af6113541f796041f142b85e90e27800" } }, { "id": "btoa", "type": "snippetListing", "title": "btoa", "attributes": { "text": "Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data.\n\nCreate a `Buffer` for the given string with binary encoding and use `Buffer.toString('base64')` to return the encoded string.\n\n", "tags": [ "node", "string", "utility", "beginner" ] }, "meta": { "hash": "1c7836009987b8b1097b54a84c38144f6cb643477f08f00b1a37e274cf0c9f78" } }, { "id": "byteSize", "type": "snippetListing", "title": "byteSize", "attributes": { "text": "Returns the length of a string in bytes.\n\nConvert a given string to a [`Blob` Object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and find its `size`.\n\n", "tags": [ "string", "beginner" ] }, "meta": { "hash": "c347c3d7b5fdc40df6d480810318d1ba644a74719bda3708b3ee3290f0ff953f" } }, { "id": "call", "type": "snippetListing", "title": "call", "attributes": { "text": "Given a key and a set of arguments, call them when given a context. Primarily useful in composition.\n\nUse a closure to call a stored key with stored arguments.\n\n", "tags": [ "adapter", "function", "intermediate" ] }, "meta": { "hash": "0a09f658c6bd2149c2a14528f12e8851e2ba02b9bd04c7df491a89f766b63083" } }, { "id": "capitalize", "type": "snippetListing", "title": "capitalize", "attributes": { "text": "Capitalizes the first letter of a string.\n\nUse array destructuring and `String.prototype.toUpperCase()` to capitalize first letter, `...rest` to get array of characters after first letter and then `Array.prototype.join('')` to make it a string again.\nOmit the `lowerRest` parameter to keep the rest of the string intact, or set it to `true` to convert to lowercase.\n\n", "tags": [ "string", "array", "intermediate" ] }, "meta": { "hash": "0c94a28b30fdfe112c8981a86868917d24cc5ddd1c84212a29783cec2d3a5ab4" } }, { "id": "capitalizeEveryWord", "type": "snippetListing", "title": "capitalizeEveryWord", "attributes": { "text": "Capitalizes the first letter of every word in a string.\n\nUse `String.prototype.replace()` to match the first character of each word and `String.prototype.toUpperCase()` to capitalize it.\n\n", "tags": [ "string", "regexp", "intermediate" ] }, "meta": { "hash": "aaf38afdc8033b2070b0e29ddb380db8570bbed490c6f39f55ff95167cdded8e" } }, { "id": "castArray", "type": "snippetListing", "title": "castArray", "attributes": { "text": "Casts the provided value as an array if it's not one.\n\nUse `Array.prototype.isArray()` to determine if `val` is an array and return it as-is or encapsulated in an array accordingly.\n\n", "tags": [ "utility", "array", "type", "beginner" ] }, "meta": { "hash": "307add91ea4d5c2a122256f799120f580ac235567523dddeeadd6500f1e81e94" } }, { "id": "chainAsync", "type": "snippetListing", "title": "chainAsync", "attributes": { "text": "Chains asynchronous functions.\n\nLoop through an array of functions containing asynchronous events, calling `next` when each asynchronous event has completed.\n\n", "tags": [ "function", "intermediate" ] }, "meta": { "hash": "cd48981af62f6ba75694f796fc5537e6af53a58045465ebd52f8bdd1a1f892af" } }, { "id": "checkProp", "type": "snippetListing", "title": "checkProp", "attributes": { "text": "Given a `predicate` function and a `prop` string, this curried function will then take an `object` to inspect by calling the property and passing it to the predicate.\n\nSummon `prop` on `obj`, pass it to a provided `predicate` function and return a masked boolean.\n\n", "tags": [ "function", "object", "utility", "beginner" ] }, "meta": { "hash": "8f90fc9af774cb790696bde174d055a366810455b17750b9397c29bd541ca034" } }, { "id": "chunk", "type": "snippetListing", "title": "chunk", "attributes": { "text": "Chunks an array into smaller arrays of a specified size.\n\nUse `Array.from()` to create a new array, that fits the number of chunks that will be produced.\nUse `Array.prototype.slice()` to map each element of the new array to a chunk the length of `size`.\nIf the original array can't be split evenly, the final chunk will contain the remaining elements.\n\n", "tags": [ "array", "intermediate" ] }, "meta": { "hash": "4af3783b8b490cdf70853b0a01780244556a18a7398f5bef123e4f39edbadebe" } }, { "id": "clampNumber", "type": "snippetListing", "title": "clampNumber", "attributes": { "text": "Clamps `num` within the inclusive range specified by the boundary values `a` and `b`.\n\nIf `num` falls within the range, return `num`.\nOtherwise, return the nearest number in the range.\n\n", "tags": [ "math", "beginner" ] }, "meta": { "hash": "32fc5181c38c6d5bb16ac7373b68ad971c6b3cff6b80aee8cb69c296d47d0607" } }, { "id": "cloneRegExp", "type": "snippetListing", "title": "cloneRegExp", "attributes": { "text": "Clones a regular expression.\n\nUse `new RegExp()`, `RegExp.source` and `RegExp.flags` to clone the given regular expression.\n\n", "tags": [ "utility", "regexp", "intermediate" ] }, "meta": { "hash": "3b7e9a506c229c792da093336574e3524cd1a8c794d18fc450f469f171ff83cf" } }, { "id": "coalesce", "type": "snippetListing", "title": "coalesce", "attributes": { "text": "Returns the first non-null/undefined argument.\n\nUse `Array.prototype.find()` to return the first non `null`/`undefined` argument.\n\n", "tags": [ "utility", "beginner" ] }, "meta": { "hash": "52b7275a934c85ccab144c174f07cf0f3aaf8b1dee913abab020b1be9666d021" } }, { "id": "coalesceFactory", "type": "snippetListing", "title": "coalesceFactory", "attributes": { "text": "Returns a customized coalesce function that returns the first argument that returns `true` from the provided argument validation function.\n\nUse `Array.prototype.find()` to return the first argument that returns `true` from the provided argument validation function.\n\n", "tags": [ "utility", "intermediate" ] }, "meta": { "hash": "b85ec57d815ff34ba3906195440fce5d2ad9f33b64d7d96159c0e1125fee283c" } }, { "id": "collectInto", "type": "snippetListing", "title": "collectInto", "attributes": { "text": "Changes a function that accepts an array into a variadic function.\n\nGiven a function, return a closure that collects all inputs into an array-accepting function.\n\n", "tags": [ "adapter", "function", "array", "intermediate" ] }, "meta": { "hash": "952f58128e70180fd6a1406562cac8781c92d258dfa0993cfb9cc6c968b0abfb" } }, { "id": "colorize", "type": "snippetListing", "title": "colorize", "attributes": { "text": "Add special characters to text to print in color in the console (combined with `console.log()`).\n\nUse template literals and special characters to add the appropriate color code to the string output.\nFor background colors, add a special character that resets the background color at the end of the string.\n\n", "tags": [ "node", "utility", "string", "intermediate" ] }, "meta": { "hash": "1ce726b8cbc9f87ff8ff6d68e0678325523b1118fa038b97f53ddad9031dbe23" } }, { "id": "compact", "type": "snippetListing", "title": "compact", "attributes": { "text": "Removes falsy values from an array.\n\nUse `Array.prototype.filter()` to filter out falsy values (`false`, `null`, `0`, `\"\"`, `undefined`, and `NaN`).\n\n", "tags": [ "array", "beginner" ] }, "meta": { "hash": "fdd7fd5631e5c1b541eff445f3388488dc060d435e339d9c0f1f257d5733e2fe" } }, { "id": "compactWhitespace", "type": "snippetListing", "title": "compactWhitespace", "attributes": { "text": "Returns a string with whitespaces compacted.\n\nUse `String.prototype.replace()` with a regular expression to replace all occurrences of 2 or more whitespace characters with a single space.\n\n", "tags": [ "string", "regexp", "beginner" ] }, "meta": { "hash": "7b6007e94c262a97cfab69ddb111d101103c095dbf2fd7680053d8733e6f2914" } }, { "id": "compose", "type": "snippetListing", "title": "compose", "attributes": { "text": "Performs right-to-left function composition.\n\nUse `Array.prototype.reduce()` to perform right-to-left function composition.\nThe last (rightmost) function can accept one or more arguments; the remaining functions must be unary.\n\n", "tags": [ "function", "intermediate" ] }, "meta": { "hash": "200b26d1e1016c56ba796665b94266e57127b6bcf23bb00b702df01676f95443" } }, { "id": "composeRight", "type": "snippetListing", "title": "composeRight", "attributes": { "text": "Performs left-to-right function composition.\n\nUse `Array.prototype.reduce()` to perform left-to-right function composition.\nThe first (leftmost) function can accept one or more arguments; the remaining functions must be unary.\n\n", "tags": [ "function", "intermediate" ] }, "meta": { "hash": "90b2780517322e1c847b7e7ae5325f1e69765eb22b72cf3472e1cd7d07f06347" } }, { "id": "converge", "type": "snippetListing", "title": "converge", "attributes": { "text": "Accepts a converging function and a list of branching functions and returns a function that applies each branching function to the arguments and the results of the branching functions are passed as arguments to the converging function.\n\nUse `Array.prototype.map()` and `Function.prototype.apply()` to apply each function to the given arguments.\nUse the spread operator (`...`) to call `coverger` with the results of all other functions.\n\n", "tags": [ "function", "intermediate" ] }, "meta": { "hash": "37cf3e2c4a2b41cb94eab31680088761236be2fc817c2c4322a0f9f1a16ae475" } }, { "id": "copyToClipboard", "type": "snippetListing", "title": "copyToClipboard", "attributes": { "text": "⚠️ **NOTICE:** The same functionality can be easily implemented by using the new asynchronous Clipboard API, which is still experimental but should be used in the future instead of this snippet. Find out more about it [here](https://github.com/w3c/clipboard-apis/blob/master/explainer.adoc#writing-to-the-clipboard).\n\nCopy a string to the clipboard. \nOnly works as a result of user action (i.e. inside a `click` event listener).\n\nCreate a new `