3249 lines
123 KiB
JavaScript
3249 lines
123 KiB
JavaScript
|
||
> 30-seconds-of-code@0.0.1 localizer G:\My Files\git Repositories\30-seconds-of-code
|
||
> node ./scripts/localize.js
|
||
|
||
module.exports = {
|
||
anagrams : {
|
||
description: `### anagrams
|
||
|
||
⚠️ **WARNING**: This function's execution time increases exponentially with each character. Anything more than 8 to 10 characters will cause your browser to hang as it tries to solve all the different combinations.
|
||
|
||
Generates all anagrams of a string (contains duplicates).
|
||
|
||
Use recursion.
|
||
For each letter in the given string, create all the partial anagrams for the rest of its letters.
|
||
Use \`Array.map()\` to combine the letter with each partial anagram, then \`Array.reduce()\` to combine all anagrams in one array.
|
||
Base cases are for string \`length\` equal to \`2\` or \`1\`.
|
||
|
||
`,
|
||
comments: [`// ['abc','acb','bac','bca','cab','cba']`],
|
||
hash: 'db57928e845bb3ddd75803bc9fb56e35682f0db49c44fc5bf49ce92ed7823ec2'
|
||
},
|
||
arrayToHtmlList : {
|
||
description: `### arrayToHtmlList
|
||
|
||
Converts the given array elements into \`<li>\` tags and appends them to the list of the given id.
|
||
|
||
Use \`Array.map()\` and \`document.querySelector()\` to create a list of html tags.
|
||
|
||
`,
|
||
comments: [],
|
||
hash: 'cd04af6fa6e404bd23fe048eaa3487cd3c6ca41510a1fa655562f1f021b6ea79'
|
||
},
|
||
ary : {
|
||
description: `### ary
|
||
|
||
Creates a function that accepts up to \`n\` arguments, ignoring any additional arguments.
|
||
|
||
Call the provided function, \`fn\`, with up to \`n\` arguments, using \`Array.slice(0,n)\` and the spread operator (\`...\`).
|
||
|
||
`,
|
||
comments: [`// [6, 8, 10]`],
|
||
hash: '4f3141d750bb65b9ea7749e1d87c56e20b175471218daad82a9d39b85c83709c'
|
||
},
|
||
atob : {
|
||
description: `### atob
|
||
|
||
Decodes a string of data which has been encoded using base-64 encoding.
|
||
|
||
Create a \`Buffer\` for the given string with base-64 encoding and use \`Buffer.toString('binary')\` to return the decoded string.
|
||
|
||
`,
|
||
comments: [`// 'foobar'`],
|
||
hash: '63d1284df5e152ae1017e1345be0afdfe537b8958955e8d48b1dc09096c0ddbb'
|
||
},
|
||
attempt : {
|
||
description: `### attempt
|
||
|
||
Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.
|
||
|
||
Use a \`try... catch\` block to return either the result of the function or an appropriate error.
|
||
|
||
`,
|
||
comments: [`// elements = []`],
|
||
hash: 'af5e1ebd6ac8b69a8bb7ae4411181e693e1152460d749b00e08ebb8a0eb0738d'
|
||
},
|
||
average : {
|
||
description: `### average
|
||
|
||
Returns the average of two or more numbers.
|
||
|
||
Use \`Array.reduce()\` to add each value to an accumulator, initialized with a value of \`0\`, divide by the \`length\` of the array.
|
||
|
||
`,
|
||
comments: [`// 2`,`// 2`],
|
||
hash: '9ae903bc29b9075c9326bbceb0682c697cb73ddb632a434fe8035fd2a48e54e3'
|
||
},
|
||
averageBy : {
|
||
description: `### averageBy
|
||
|
||
Returns the average of an array, after mapping each element to a value using the provided function.
|
||
|
||
Use \`Array.map()\` to map each element to the value returned by \`fn\`, \`Array.reduce()\` to add each value to an accumulator, initialized with a value of \`0\`, divide by the \`length\` of the array.
|
||
|
||
`,
|
||
comments: [`// 5`,`// 5`],
|
||
hash: 'cc0fc4d2586eed04909cbd7912008273e04b988ee41897517cf9c39f21c16d72'
|
||
},
|
||
bind : {
|
||
description: `### bind
|
||
|
||
Creates a function that invokes \`fn\` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments.
|
||
|
||
Return a \`function\` that uses \`Function.apply()\` to apply the given \`context\` to \`fn\`.
|
||
Use \`Array.concat()\` to prepend any additional supplied parameters to the arguments.
|
||
|
||
`,
|
||
comments: [`// 'hi fred!'`],
|
||
hash: '559b6272a1b9c506513617f815f128495feb27ad9b3fa807c3cdded9aae35e9d'
|
||
},
|
||
bindAll : {
|
||
description: `### bindAll
|
||
|
||
Use \`Array.forEach()\` to return a \`function\` that uses \`Function.apply()\` to apply the given context (\`obj\`) to \`fn\` for each function specified.
|
||
|
||
`,
|
||
comments: [`// Logs 'clicked docs' when clicked.`],
|
||
hash: '2d8eba637f445e60525f33ebc004a70e40b06ab4bc13f8262652535008cbb40c'
|
||
},
|
||
bindKey : {
|
||
description: `### bindKey
|
||
|
||
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.
|
||
|
||
Return a \`function\` that uses \`Function.apply()\` to bind \`context[fn]\` to \`context\`.
|
||
Use \`Array.concat()\` to prepend any additional supplied parameters to the arguments.
|
||
|
||
`,
|
||
comments: [`// 'hi fred!'`],
|
||
hash: 'ef7847ba9292b447909df4a34aba1f9227c270e53ce93c4ef18165657f03b92a'
|
||
},
|
||
bottomVisible : {
|
||
description: `### bottomVisible
|
||
|
||
Returns \`true\` if the bottom of the page is visible, \`false\` otherwise.
|
||
|
||
Use \`scrollY\`, \`scrollHeight\` and \`clientHeight\` to determine if the bottom of the page is visible.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '50d33c2e1ebb78ca9d9f1c288848082d590aded131aea41f86164af1050204ef'
|
||
},
|
||
btoa : {
|
||
description: `### btoa
|
||
|
||
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.
|
||
|
||
Create a \`Buffer\` for the given string with binary encoding and use \`Buffer.toString('base64')\` to return the encoded string.
|
||
|
||
`,
|
||
comments: [`// 'Zm9vYmFy'`],
|
||
hash: '6d50b12885716eddce47396bb755e6d3facf8dff786e6978b5402ead8f0e6990'
|
||
},
|
||
byteSize : {
|
||
description: `### byteSize
|
||
|
||
Returns the length of a string in bytes.
|
||
|
||
Convert a given string to a [\`Blob\` Object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and find its \`size\`.
|
||
|
||
`,
|
||
comments: [`//developer.mozilla.org/en-US/docs/Web/API/Blob) and find its \`size\`.`,`// 4`,`// 11`],
|
||
hash: '1848a81b6d95cc66138d877364bcbb3de7b89ebc4d2031348aa95345602f4a60'
|
||
},
|
||
call : {
|
||
description: `### call
|
||
|
||
Given a key and a set of arguments, call them when given a context. Primarily useful in composition.
|
||
|
||
Use a closure to call a stored key with stored arguments.
|
||
|
||
`,
|
||
comments: [`//[ 2, 4, 6 ]`,`//[ 2, 4, 6 ]`],
|
||
hash: '732d63737f940a76c33a42ae3a1dcbf72b93149f57e14e34e301dad7ce245236'
|
||
},
|
||
capitalize : {
|
||
description: `### capitalize
|
||
|
||
Capitalizes the first letter of a string.
|
||
|
||
Use array destructuring and \`String.toUpperCase()\` to capitalize first letter, \`...rest\` to get array of characters after first letter and then \`Array.join('')\` to make it a string again.
|
||
Omit the \`lowerRest\` parameter to keep the rest of the string intact, or set it to \`true\` to convert to lowercase.
|
||
|
||
`,
|
||
comments: [`// 'FooBar'`,`// 'Foobar'`],
|
||
hash: '225acdf8e1cbce3dba7ac8591de9d6051165523bf78e1c9b37954a9c5a267252'
|
||
},
|
||
capitalizeEveryWord : {
|
||
description: `### capitalizeEveryWord
|
||
|
||
Capitalizes the first letter of every word in a string.
|
||
|
||
Use \`String.replace()\` to match the first character of each word and \`String.toUpperCase()\` to capitalize it.
|
||
|
||
`,
|
||
comments: [`// 'Hello World!'`],
|
||
hash: 'f1ce5987c4180d806c65b415f913bb0a2dcc708ad7a5249d31f9e52d8cba30e3'
|
||
},
|
||
castArray : {
|
||
description: `### castArray
|
||
|
||
Casts the provided value as an array if it's not one.
|
||
|
||
Use \`Array.isArray()\` to determine if \`val\` is an array and return it as-is or encapsulated in an array accordingly.
|
||
|
||
`,
|
||
comments: [`// ['foo']`,`// [1]`],
|
||
hash: 'a43c8982dc21f32869d600d175ddcc0b56a24da09a629f6f3be5167bb753e189'
|
||
},
|
||
chainAsync : {
|
||
description: `### chainAsync
|
||
|
||
Chains asynchronous functions.
|
||
|
||
Loop through an array of functions containing asynchronous events, calling \`next\` when each asynchronous event has completed.
|
||
|
||
`,
|
||
comments: [],
|
||
hash: '8b6d33fba612cac3b4e97a42fc7bfaa5b52fc96a47d6e580528f6aeae789606d'
|
||
},
|
||
chunk : {
|
||
description: `### chunk
|
||
|
||
Chunks an array into smaller arrays of a specified size.
|
||
|
||
Use \`Array.from()\` to create a new array, that fits the number of chunks that will be produced.
|
||
Use \`Array.slice()\` to map each element of the new array to a chunk the length of \`size\`.
|
||
If the original array can't be split evenly, the final chunk will contain the remaining elements.
|
||
|
||
`,
|
||
comments: [`// [[1,2],[3,4],[5]]`],
|
||
hash: '08ec92acf3f5d606ad2358a30d40f18b2cb78b4e48d31599bb022c749cc6c9c2'
|
||
},
|
||
clampNumber : {
|
||
description: `### clampNumber
|
||
|
||
Clamps \`num\` within the inclusive range specified by the boundary values \`a\` and \`b\`.
|
||
|
||
If \`num\` falls within the range, return \`num\`.
|
||
Otherwise, return the nearest number in the range.
|
||
|
||
`,
|
||
comments: [`// 3`,`// -1`],
|
||
hash: '09c31287b551db9961ca3f15ec3bbc53965edf318ef50c05fac8cfd52919c2e9'
|
||
},
|
||
cloneRegExp : {
|
||
description: `### cloneRegExp
|
||
|
||
Clones a regular expression.
|
||
|
||
Use \`new RegExp()\`, \`RegExp.source\` and \`RegExp.flags\` to clone the given regular expression.
|
||
|
||
`,
|
||
comments: [`// /lorem ipsum/gi`],
|
||
hash: 'ee8e6e19269907273e58f0820bdbfc57022b6673453283058aedbbfc76586658'
|
||
},
|
||
coalesce : {
|
||
description: `### coalesce
|
||
|
||
Returns the first non-null/undefined argument.
|
||
|
||
Use \`Array.find()\` to return the first non \`null\`/\`undefined\` argument.
|
||
|
||
`,
|
||
comments: [`// ""`],
|
||
hash: 'e0623f0679ae4ec6af58ad00526ba69458fce3bb442e86796d91638e45d8f509'
|
||
},
|
||
coalesceFactory : {
|
||
description: `### coalesceFactory
|
||
|
||
Returns a customized coalesce function that returns the first argument that returns \`true\` from the provided argument validation function.
|
||
|
||
Use \`Array.find()\` to return the first argument that returns \`true\` from the provided argument validation function.
|
||
|
||
`,
|
||
comments: [`// "Waldo"`],
|
||
hash: 'a7874701262b9deec699ed856a358e40fd5de71524a175efe7a9a76a9936d3ad'
|
||
},
|
||
collectInto : {
|
||
description: `### collectInto
|
||
|
||
Changes a function that accepts an array into a variadic function.
|
||
|
||
Given a function, return a closure that collects all inputs into an array-accepting function.
|
||
|
||
`,
|
||
comments: [`// [1, 2, 3] (after about 2 seconds)`],
|
||
hash: '6b57cac68ad177d8fbb30e9c586f8f9c088acf755c6c956b5387441ea3850fce'
|
||
},
|
||
colorize : {
|
||
description: `### colorize
|
||
|
||
Add special characters to text to print in color in the console (combined with \`console.log()\`).
|
||
|
||
Use template literals and special characters to add the appropriate color code to the string output.
|
||
For background colors, add a special character that resets the background color at the end of the string.
|
||
|
||
`,
|
||
comments: [`// 'foo' (red letters)`,`// 'foo bar' (blue background)`,`// 'foo bar' (first word in yellow letters, second word in green letters, white background for both)`],
|
||
hash: '4f42f00e7d675d21829a5fcd2ab2e3fa2058d1c1b1d6850ff28f2a424364593e'
|
||
},
|
||
compact : {
|
||
description: `### compact
|
||
|
||
Removes falsey values from an array.
|
||
|
||
Use \`Array.filter()\` to filter out falsey values (\`false\`, \`null\`, \`0\`, \`""\`, \`undefined\`, and \`NaN\`).
|
||
|
||
`,
|
||
comments: [`// [ 1, 2, 3, 'a', 's', 34 ]`],
|
||
hash: '9e8d5592a9de422eff555d3e3e27779d6f1a6cd06de0461c3c0799283348332c'
|
||
},
|
||
compose : {
|
||
description: `### compose
|
||
|
||
Performs right-to-left function composition.
|
||
|
||
Use \`Array.reduce()\` to perform right-to-left function composition.
|
||
The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.
|
||
|
||
`,
|
||
comments: [`// 15`],
|
||
hash: 'eadb3dc774a236e7c0255a2fb1e203eaa390eb50fcff2a410284557385134f58'
|
||
},
|
||
composeRight : {
|
||
description: `### composeRight
|
||
|
||
Performs left-to-right function composition.
|
||
|
||
Use \`Array.reduce()\` to perform left-to-right function composition.
|
||
The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.
|
||
|
||
`,
|
||
comments: [`// 9`],
|
||
hash: '8504d35e91465faf7d001d829b855dddb2672882699328ae8c90520c8f59eaf8'
|
||
},
|
||
converge : {
|
||
description: `### converge
|
||
|
||
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.
|
||
|
||
Use \`Array.map()\` and \`Function.apply()\` to apply each function to the given arguments.
|
||
Use the spread operator (\`...\`) to call \`coverger\` with the results of all other functions.
|
||
|
||
`,
|
||
comments: [`// 4`],
|
||
hash: '198b90bf166c74f511a66cfcb6c2e55aab7dafd600d3c53f2b26d9f8a0aade0f'
|
||
},
|
||
copyToClipboard : {
|
||
description: `### copyToClipboard
|
||
|
||
Copy a string to the clipboard. Only works as a result of user action (i.e. inside a \`click\` event listener).
|
||
|
||
Create a new \`<textarea>\` element, fill it with the supplied data and add it to the HTML document.
|
||
Use \`Selection.getRangeAt()\`to store the selected range (if any).
|
||
Use \`document.execCommand('copy')\` to copy to the clipboard.
|
||
Remove the \`<textarea>\` element from the HTML document.
|
||
Finally, use \`Selection().addRange()\` to recover the original selected range (if any).
|
||
|
||
`,
|
||
comments: [`// 'Lorem ipsum' copied to clipboard.`],
|
||
hash: 'c496300a947ef9aabbe72f79c7ba0ca85c3a816eb54cbc8bb44ea5830b5380c9'
|
||
},
|
||
countBy : {
|
||
description: `### countBy
|
||
|
||
Groups the elements of an array based on the given function and returns the count of elements in each group.
|
||
|
||
Use \`Array.map()\` to map the values of an array to a function or property name.
|
||
Use \`Array.reduce()\` to create an object, where the keys are produced from the mapped results.
|
||
|
||
`,
|
||
comments: [`// {4: 1, 6: 2}`,`// {3: 2, 5: 1}`],
|
||
hash: 'f2d7ea332efad9bcf0142a12080d7790be797ed7ac4bdbe5b2aa315c450568b6'
|
||
},
|
||
countOccurrences : {
|
||
description: `### countOccurrences
|
||
|
||
Counts the occurrences of a value in an array.
|
||
|
||
Use \`Array.reduce()\` to increment a counter each time you encounter the specific value inside the array.
|
||
|
||
`,
|
||
comments: [`// 3`],
|
||
hash: '9a1cb0654d5660678f12f9eb797ae2e2b20bc29743f2c2197670399941349fa1'
|
||
},
|
||
createElement : {
|
||
description: `### createElement
|
||
|
||
Creates an element from a string (without appending it to the document).
|
||
If the given string contains multiple elements, only the first one will be returned.
|
||
|
||
Use \`document.createElement()\` to create a new element.
|
||
Set its \`innerHTML\` to the string supplied as the argument.
|
||
Use \`ParentNode.firstElementChild\` to return the element version of the string.
|
||
|
||
`,
|
||
comments: [`// 'container'`],
|
||
hash: 'c700b4d0695f1916842fa8b2b68e63a3735b9b87681e54addb23e92c6404a5f5'
|
||
},
|
||
createEventHub : {
|
||
description: `### createEventHub
|
||
|
||
Creates a pub/sub ([publish–subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) event hub with \`emit\`, \`on\`, and \`off\` methods.
|
||
|
||
Use \`Object.create(null)\` to create an empty \`hub\` object that does not inherit properties from \`Object.prototype\`.
|
||
For \`emit\`, resolve the array of handlers based on the \`event\` argument and then run each one with \`Array.forEach()\` by passing in the data as an argument.
|
||
For \`on\`, create an array for the event if it does not yet exist, then use \`Array.push()\` to add the handler
|
||
to the array.
|
||
For \`off\`, use \`Array.findIndex()\` to find the index of the handler in the event array and remove it using \`Array.splice()\`.
|
||
|
||
`,
|
||
comments: [`//en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) event hub with \`emit\`, \`on\`, and \`off\` methods.`,`// Subscribe: listen for different types of events`,`// Publish: emit events to invoke all handlers subscribed to them, passing the data to them as an argument`,`// logs 'hello world' and 'Message event fired'`,`// logs the object and 'Message event fired'`,`// \`increment\` variable is now 1`,`// Unsubscribe: stop a specific handler from listening to the 'message' event`],
|
||
hash: 'e952a30a27c1465ea9ac465d4b7de3f9dda6e58279c176bc7c0e98fb6d99f1fc'
|
||
},
|
||
currentURL : {
|
||
description: `### currentURL
|
||
|
||
Returns the current URL.
|
||
|
||
Use \`window.location.href\` to get current URL.
|
||
|
||
`,
|
||
comments: [`// 'https://google.com'`],
|
||
hash: '84e59a5cb6f22eb0bd1595bd6cd4f6be60d5b6d8c4adf964f6d2d84d320bd1d6'
|
||
},
|
||
curry : {
|
||
description: `### curry
|
||
|
||
Curries a function.
|
||
|
||
Use recursion.
|
||
If the number of provided arguments (\`args\`) is sufficient, call the passed function \`fn\`.
|
||
Otherwise, return a curried function \`fn\` that expects the rest of the arguments.
|
||
If you want to curry a function that accepts a variable number of arguments (a variadic function, e.g. \`Math.min()\`), you can optionally pass the number of arguments to the second parameter \`arity\`.
|
||
|
||
`,
|
||
comments: [`// 1024`,`// 2`],
|
||
hash: '0ae620833c37934878ad75bddab17d1fa5b40e9a13282216661a9da5f337b2a8'
|
||
},
|
||
debounce : {
|
||
description: `### debounce
|
||
|
||
Creates a debounced function that delays invoking the provided function until after \`wait\` milliseconds have elapsed since the last time the debounced function was invoked.
|
||
|
||
Use \`setTimeout()\` and \`clearTimeout()\` to debounce the given method, \`fn\`.
|
||
Use \`Function.apply()\` to apply the \`this\` context to the function and provide the necessary \`arguments\`.
|
||
Omit the second argument, \`wait\`, to set the timeout at a default of 0 ms.
|
||
|
||
`,
|
||
comments: [`// Will log the window dimensions at most every 250ms`],
|
||
hash: '1d4123922a86704d1acc0ac179415200f967fdd0d77a8193156a55c70a9ec79b'
|
||
},
|
||
decapitalize : {
|
||
description: `### decapitalize
|
||
|
||
Decapitalizes the first letter of a string.
|
||
|
||
Use array destructuring and \`String.toLowerCase()\` to decapitalize first letter, \`...rest\` to get array of characters after first letter and then \`Array.join('')\` to make it a string again.
|
||
Omit the \`upperRest\` parameter to keep the rest of the string intact, or set it to \`true\` to convert to uppercase.
|
||
|
||
`,
|
||
comments: [`// 'fooBar'`,`// 'fOOBAR'`],
|
||
hash: '8c32253128ce65b3b13b389f9632985ea507f23da199b87d448dd4f7b5ae2dad'
|
||
},
|
||
deepClone : {
|
||
description: `### deepClone
|
||
|
||
Creates a deep clone of an object.
|
||
|
||
Use recursion.
|
||
Use \`Object.assign()\` and an empty object (\`{}\`) to create a shallow clone of the original.
|
||
Use \`Object.keys()\` and \`Array.forEach()\` to determine which key-value pairs need to be deep cloned.
|
||
|
||
`,
|
||
comments: [`// a !== b, a.obj !== b.obj`],
|
||
hash: 'b308891e311b9a90a4868d2650b08c564cac9ed0ccb2ef3900adf65c3441d970'
|
||
},
|
||
deepFlatten : {
|
||
description: `### deepFlatten
|
||
|
||
Deep flattens an array.
|
||
|
||
Use recursion.
|
||
Use \`Array.concat()\` with an empty array (\`[]\`) and the spread operator (\`...\`) to flatten an array.
|
||
Recursively flatten each element that is an array.
|
||
|
||
`,
|
||
comments: [`// [1,2,3,4,5]`],
|
||
hash: '842f1f5ba5469cd275b51861866bdfbe3a89e461e996e32e05ff5916406e7d07'
|
||
},
|
||
defaults : {
|
||
description: `### defaults
|
||
|
||
Assigns default values for all properties in an object that are \`undefined\`.
|
||
|
||
Use \`Object.assign()\` to create a new empty object and copy the original one to maintain key order, use \`Array.reverse()\` and the spread operator \`...\` to combine the default values from left to right, finally use \`obj\` again to overwrite properties that originally had a value.
|
||
|
||
`,
|
||
comments: [`// { a: 1, b: 2 }`],
|
||
hash: '3ad960a2f802dcc9ab494a4d4010e01fe41841fddf250c76e6ca85d0f936fda0'
|
||
},
|
||
defer : {
|
||
description: `### defer
|
||
|
||
Defers invoking a function until the current call stack has cleared.
|
||
|
||
Use \`setTimeout()\` with a timeout of 1ms to add a new event to the browser event queue and allow the rendering engine to complete its work. Use the spread (\`...\`) operator to supply the function with an arbitrary number of arguments.
|
||
|
||
`,
|
||
comments: [`// Example A:`,`// logs 'b' then 'a'`,`// Example B:`,`//Browser will not update the HTML until this has finished`,`// Browser will update the HTML then run the function`],
|
||
hash: 'ec8e56228f91ef3fab2b4895912ab082cfc37f617b10b82304beb9239c3fd8d6'
|
||
},
|
||
delay : {
|
||
description: `### delay
|
||
|
||
Invokes the provided function after \`wait\` milliseconds.
|
||
|
||
Use \`setTimeout()\` to delay execution of \`fn\`.
|
||
Use the spread (\`...\`) operator to supply the function with an arbitrary number of arguments.
|
||
|
||
`,
|
||
comments: [`// Logs 'later' after one second.`],
|
||
hash: 'bcfc86542ccf08bcd721e099f4db41618737a3d619052045a2ec7556e62d1322'
|
||
},
|
||
detectDeviceType : {
|
||
description: `### detectDeviceType
|
||
|
||
Detects wether the website is being opened in a mobile device or a desktop/laptop.
|
||
|
||
Use a regular expression to test the \`navigator.userAgent\` property to figure out if the device is a mobile device or a desktop/laptop.
|
||
|
||
`,
|
||
comments: [`// "Mobile" or "Desktop"`],
|
||
hash: 'fb87eebb59abc6428f949d510918e68d6e2483f75527fa37cb6fb175c6eadd06'
|
||
},
|
||
difference : {
|
||
description: `### difference
|
||
|
||
Returns the difference between two arrays.
|
||
|
||
Create a \`Set\` from \`b\`, then use \`Array.filter()\` on \`a\` to only keep values not contained in \`b\`.
|
||
|
||
`,
|
||
comments: [`// [3]`],
|
||
hash: '9f2fe2455a82dae09790f579684d2c6a9b9dca4a43825a69e08911a635eeafdc'
|
||
},
|
||
differenceBy : {
|
||
description: `### differenceBy
|
||
|
||
Returns the difference between two arrays, after applying the provided function to each array element of both.
|
||
|
||
Create a \`Set\` by applying \`fn\` to each element in \`b\`, then use \`Array.filter()\` in combination with \`fn\` on \`a\` to only keep values not contained in the previously created set.
|
||
|
||
`,
|
||
comments: [`// [1.2]`,`// [ { x: 2 } ]`],
|
||
hash: 'b4336c95ff54a4d272e5a367b09d0439aeaf349bb434cd23827c5521c73f92df'
|
||
},
|
||
differenceWith : {
|
||
description: `### differenceWith
|
||
|
||
Filters out all values from an array for which the comparator function does not return \`true\`.
|
||
|
||
Use \`Array.filter()\` and \`Array.findIndex()\` to find the appropriate values.
|
||
|
||
`,
|
||
comments: [`// [1, 1.2]`],
|
||
hash: 'b55661a99bc22533e51dd7b41162081204d468d1b6a40d2078464aaf5421cdbf'
|
||
},
|
||
digitize : {
|
||
description: `### digitize
|
||
|
||
Converts a number to an array of digits.
|
||
|
||
Convert the number to a string, using the spread operator (\`...\`) to build an array.
|
||
Use \`Array.map()\` and \`parseInt()\` to transform each value to an integer.
|
||
|
||
`,
|
||
comments: [`// [1, 2, 3]`],
|
||
hash: '45d30539d39b085e88b7f8d4501e807a8f6c6a6036d6932eae540e6c6d8ea6ac'
|
||
},
|
||
distance : {
|
||
description: `### distance
|
||
|
||
Returns the distance between two points.
|
||
|
||
Use \`Math.hypot()\` to calculate the Euclidean distance between two points.
|
||
|
||
`,
|
||
comments: [`// 2.23606797749979`],
|
||
hash: 'ad8cffd630645e104eaaa17c0813f4bfc16167ea582553faed58cb872c8d1608'
|
||
},
|
||
drop : {
|
||
description: `### drop
|
||
|
||
Returns a new array with \`n\` elements removed from the left.
|
||
|
||
Use \`Array.slice()\` to slice the remove the specified number of elements from the left.
|
||
|
||
`,
|
||
comments: [`// [2,3]`,`// [3]`,`// []`],
|
||
hash: '9163978243a159591880152728093865f321333d9a0acf461e7dd80b623592d8'
|
||
},
|
||
dropRight : {
|
||
description: `### dropRight
|
||
|
||
Returns a new array with \`n\` elements removed from the right.
|
||
|
||
Use \`Array.slice()\` to slice the remove the specified number of elements from the right.
|
||
|
||
`,
|
||
comments: [`// [1,2]`,`// [1]`,`// []`],
|
||
hash: '1c8b405a85997397f26f70b5cbc76d1c0cfd38ebce50dad8b40fe0870437b5cf'
|
||
},
|
||
dropRightWhile : {
|
||
description: `### dropRightWhile
|
||
|
||
Removes elements from the end of an array until the passed function returns \`true\`. Returns the remaining elements in the array.
|
||
|
||
Loop through the array, using \`Array.slice()\` to drop the last element of the array until the returned value from the function is \`true\`.
|
||
Returns the remaining elements.
|
||
|
||
`,
|
||
comments: [`// [1, 2]`],
|
||
hash: '8b3d8c14f35432e1032e34ddd9cd16fb17a1ced24f0a91bc0693fab8c199a062'
|
||
},
|
||
dropWhile : {
|
||
description: `### dropWhile
|
||
|
||
Removes elements in an array until the passed function returns \`true\`. Returns the remaining elements in the array.
|
||
|
||
Loop through the array, using \`Array.slice()\` to drop the first element of the array until the returned value from the function is \`true\`.
|
||
Returns the remaining elements.
|
||
|
||
`,
|
||
comments: [`// [3,4]`],
|
||
hash: 'f7a78522b1e35cf2efe8ad787af3d9f68b26e272b7b58cf18c50d2b3ebf5bf91'
|
||
},
|
||
elementIsVisibleInViewport : {
|
||
description: `### elementIsVisibleInViewport
|
||
|
||
Returns \`true\` if the element specified is visible in the viewport, \`false\` otherwise.
|
||
|
||
Use \`Element.getBoundingClientRect()\` and the \`window.inner(Width|Height)\` values
|
||
to determine if a given element is visible in the viewport.
|
||
Omit the second argument to determine if the element is entirely visible, or specify \`true\` to determine if
|
||
it is partially visible.
|
||
|
||
`,
|
||
comments: [`// e.g. 100x100 viewport and a 10x10px element at position {top: -1, left: 0, bottom: 9, right: 10}`,`// false - (not fully visible)`,`// true - (partially visible)`],
|
||
hash: 'ecffed7e920d056fa6322754ee503b99f04b86163a551e1012a2e158d09e1c90'
|
||
},
|
||
elo : {
|
||
description: `### elo
|
||
|
||
Computes the new ratings between two or more opponents using the [Elo rating system](https://en.wikipedia.org/wiki/Elo_rating_system). It takes an array
|
||
of pre-ratings and returns an array containing post-ratings.
|
||
The array should be ordered from best performer to worst performer (winner -> loser).
|
||
|
||
Use the exponent \`**\` operator and math operators to compute the expected score (chance of winning).
|
||
of each opponent and compute the new rating for each.
|
||
Loop through the ratings, using each permutation to compute the post-Elo rating for each player in a pairwise fashion.
|
||
Omit the second argument to use the default \`kFactor\` of 32.
|
||
|
||
`,
|
||
comments: [`//en.wikipedia.org/wiki/Elo_rating_system). It takes an array`,`// Standard 1v1s`,`// [1216, 1184]`,`// [1232, 1168]`,`// 4 player FFA, all same rank`,`// [1246, 1215, 1185, 1154]`],
|
||
hash: 'd0c2fc6078f3eddcc10beb2753206bf9574d3c04fd498e48d4a765d6807aa9fd'
|
||
},
|
||
equals : {
|
||
description: `### equals
|
||
|
||
Performs a deep comparison between two values to determine if they are equivalent.
|
||
|
||
Check if the two values are identical, if they are both \`Date\` objects with the same time, using \`Date.getTime()\` or if they are both non-object values with an equivalent value (strict comparison).
|
||
Check if only one value is \`null\` or \`undefined\` or if their prototypes differ.
|
||
If none of the above conditions are met, use \`Object.keys()\` to check if both values have the same number of keys, then use \`Array.every()\` to check if every key in the first value exists in the second one and if they are equivalent by calling this method recursively.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '0b2d73c3cf1c6817ecbaf5de7b579c4a648caa2b8a638c4ea27f14574be0e9fd'
|
||
},
|
||
escapeHTML : {
|
||
description: `### escapeHTML
|
||
|
||
Escapes a string for use in HTML.
|
||
|
||
Use \`String.replace()\` with a regexp that matches the characters that need to be escaped, using a callback function to replace each character instance with its associated escaped character using a dictionary (object).
|
||
|
||
`,
|
||
comments: [`// '<a href="#">Me & you</a>'`],
|
||
hash: '5d5e09bc3a378d8cd1b5ac1f0de3d0b34e1af32c9b97f3878b9d103ebbd778d5'
|
||
},
|
||
escapeRegExp : {
|
||
description: `### escapeRegExp
|
||
|
||
Escapes a string to use in a regular expression.
|
||
|
||
Use \`String.replace()\` to escape special characters.
|
||
|
||
`,
|
||
comments: [`// \\(test\\)`],
|
||
hash: '29c6277721887e2813511cda714639223a7ee175da509cb789809054517b9f14'
|
||
},
|
||
everyNth : {
|
||
description: `### everyNth
|
||
|
||
Returns every nth element in an array.
|
||
|
||
Use \`Array.filter()\` to create a new array that contains every nth element of a given array.
|
||
|
||
`,
|
||
comments: [`// [ 2, 4, 6 ]`],
|
||
hash: '98c8c8e152c498695b1a0ac8a4ef9ce91ddca13a476edf21105924f297deb68d'
|
||
},
|
||
extendHex : {
|
||
description: `### extendHex
|
||
|
||
Extends a 3-digit color code to a 6-digit color code.
|
||
|
||
Use \`Array.map()\`, \`String.split()\` and \`Array.join()\` to join the mapped array for converting a 3-digit RGB notated hexadecimal color-code to the 6-digit form.
|
||
\`Array.slice()\` is used to remove \`#\` from string start since it's added once.
|
||
|
||
`,
|
||
comments: [`// '#0033ff'`,`// '#0055aa'`],
|
||
hash: 'af0ffcf6ac451953aa9ab972c9379c6ff3cefc2a80aeb70e5363b7778843efde'
|
||
},
|
||
factorial : {
|
||
description: `### factorial
|
||
|
||
Calculates the factorial of a number.
|
||
|
||
Use recursion.
|
||
If \`n\` is less than or equal to \`1\`, return \`1\`.
|
||
Otherwise, return the product of \`n\` and the factorial of \`n - 1\`.
|
||
Throws an exception if \`n\` is a negative number.
|
||
|
||
`,
|
||
comments: [`// 720`],
|
||
hash: '07eeb5e1e6437844c4ceb55c005e338a6aadd023d079060abbcd99261316e9ed'
|
||
},
|
||
fibonacci : {
|
||
description: `### fibonacci
|
||
|
||
Generates an array, containing the Fibonacci sequence, up until the nth term.
|
||
|
||
Create an empty array of the specific length, initializing the first two values (\`0\` and \`1\`).
|
||
Use \`Array.reduce()\` to add values into the array, using the sum of the last two values, except for the first two.
|
||
|
||
`,
|
||
comments: [`// [0, 1, 1, 2, 3, 5]`],
|
||
hash: '8e8577bbcf3ca98fe251070de239b3823fa0d9293227881c0a9e0ccf31e55c46'
|
||
},
|
||
filterNonUnique : {
|
||
description: `### filterNonUnique
|
||
|
||
Filters out the non-unique values in an array.
|
||
|
||
Use \`Array.filter()\` for an array containing only the unique values.
|
||
|
||
`,
|
||
comments: [`// [1,3,5]`],
|
||
hash: '010c054cfd578bee61c031396e068039227d1233e55010b53b400e02ae96c718'
|
||
},
|
||
findKey : {
|
||
description: `### findKey
|
||
|
||
Returns the first key that satisfies the provided testing function. Otherwise \`undefined\` is returned.
|
||
|
||
Use \`Object.keys(obj)\` to get all the properties of the object, \`Array.find()\` to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.
|
||
|
||
`,
|
||
comments: [`// 'barney'`],
|
||
hash: 'fd600ccac1652119c9b6b78b3b125593137cf5e88841d70dfab2043514fc589c'
|
||
},
|
||
findLast : {
|
||
description: `### findLast
|
||
|
||
Returns the last element for which the provided function returns a truthy value.
|
||
|
||
Use \`Array.filter()\` to remove elements for which \`fn\` returns falsey values, \`Array.slice(-1)\` to get the last one.
|
||
|
||
`,
|
||
comments: [`// 3`],
|
||
hash: '1e0eb991adc3770a0e9b73f9ef56677df1e854decf769563a0983ea46f358d7f'
|
||
},
|
||
findLastIndex : {
|
||
description: `### findLastIndex
|
||
|
||
Returns the index of the last element for which the provided function returns a truthy value.
|
||
|
||
Use \`Array.map()\` to map each element to an array with its index and value.
|
||
Use \`Array.filter()\` to remove elements for which \`fn\` returns falsey values, \`Array.slice(-1)\` to get the last one.
|
||
|
||
`,
|
||
comments: [`// 2 (index of the value 3)`],
|
||
hash: '3600152d1379e251debfc76123694db973984e70e5428aa8a69df25948b8f493'
|
||
},
|
||
findLastKey : {
|
||
description: `### findLastKey
|
||
|
||
Returns the last key that satisfies the provided testing function. Otherwise \`undefined\` is returned.
|
||
|
||
Use \`Object.keys(obj)\` to get all the properties of the object, \`Array.reverse()\` to reverse their order and \`Array.find()\` to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.
|
||
|
||
`,
|
||
comments: [`// 'pebbles'`],
|
||
hash: '3aa6c03b0fc615df03351cb3ee9f8cce798d113449b604cebd268c2f508945de'
|
||
},
|
||
flatten : {
|
||
description: `### flatten
|
||
|
||
Flattens an array up to the specified depth.
|
||
|
||
Use recursion, decrementing \`depth\` by 1 for each level of depth.
|
||
Use \`Array.reduce()\` and \`Array.concat()\` to merge elements or arrays.
|
||
Base case, for \`depth\` equal to \`1\` stops recursion.
|
||
Omit the second argument, \`depth\` to flatten only to a depth of \`1\` (single flatten).
|
||
|
||
`,
|
||
comments: [`// [1, 2, 3, 4]`,`// [1, 2, 3, [4, 5], 6, 7, 8]`],
|
||
hash: 'fd7dcf06a4a4e4e1aa88b4f66730ff0f018afb59e0de70d860fe38fa125f86be'
|
||
},
|
||
flattenObject : {
|
||
description: `### flattenObject
|
||
|
||
Flatten an object with the paths for keys.
|
||
|
||
Use recursion.
|
||
Use \`Object.keys(obj)\` combined with \`Array.reduce()\` to convert every leaf node to a flattened path node.
|
||
If the value of a key is an object, the function calls itself with the appropriate \`prefix\` to create the path using \`Object.assign()\`.
|
||
Otherwise, it adds the appropriate prefixed key-value pair to the accumulator object.
|
||
You should always omit the second argument, \`prefix\`, unless you want every key to have a prefix.
|
||
|
||
`,
|
||
comments: [`// { 'a.b.c': 1, d: 1 }`],
|
||
hash: '1627897681c3f7250287eef16e3d326626b0a9b6369687d21a511c0b057dadd9'
|
||
},
|
||
flip : {
|
||
description: `### flip
|
||
|
||
Flip takes a function as an argument, then makes the first argument the last.
|
||
|
||
Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest.
|
||
|
||
`,
|
||
comments: [`// == b`,`// == b`],
|
||
hash: '57a42eb12cc7d4535c25d9945db9abb115ca9520e298fbaed64549ee22ac76aa'
|
||
},
|
||
forEachRight : {
|
||
description: `### forEachRight
|
||
|
||
Executes a provided function once for each array element, starting from the array's last element.
|
||
|
||
Use \`Array.slice(0)\` to clone the given array, \`Array.reverse()\` to reverse it and \`Array.forEach()\` to iterate over the reversed array.
|
||
|
||
`,
|
||
comments: [`// '4', '3', '2', '1'`],
|
||
hash: '80578fdbb56c0becb3bee0011d5d4e2fb650b78d9b66f9f8c31609fb53d8cab7'
|
||
},
|
||
formatDuration : {
|
||
description: `### formatDuration
|
||
|
||
Returns the human readable format of the given number of milliseconds.
|
||
|
||
Divide \`ms\` with the appropriate values to obtain the appropriate values for \`day\`, \`hour\`, \`minute\`, \`second\` and \`millisecond\`.
|
||
Use \`Object.entries()\` with \`Array.filter()\` to keep only non-zero values.
|
||
Use \`Array.map()\` to create the string for each value, pluralizing appropriately.
|
||
Use \`String.join(', ')\` to combine the values into a string.
|
||
|
||
`,
|
||
comments: [`// '1 second, 1 millisecond'`,`// '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds'`],
|
||
hash: 'c68815d428595500e504e347900004e352397f56072a6bc9040909230a621515'
|
||
},
|
||
forOwn : {
|
||
description: `### forOwn
|
||
|
||
Iterates over all own properties of an object, running a callback for each one.
|
||
|
||
Use \`Object.keys(obj)\` to get all the properties of the object, \`Array.forEach()\` to run the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.
|
||
|
||
`,
|
||
comments: [`// 'bar', 1`],
|
||
hash: '425efab14b8655ac4647e2dc601d0fca7ae583eb913699c950323244fb473c1d'
|
||
},
|
||
forOwnRight : {
|
||
description: `### forOwnRight
|
||
|
||
Iterates over all own properties of an object in reverse, running a callback for each one.
|
||
|
||
Use \`Object.keys(obj)\` to get all the properties of the object, \`Array.reverse()\` to reverse their order and \`Array.forEach()\` to run the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.
|
||
|
||
`,
|
||
comments: [`// 1, 'bar'`],
|
||
hash: 'f4213d4ac1338cab9f635c51efe440ca02c7c26eb1319e9274b36f5b4ce9971b'
|
||
},
|
||
fromCamelCase : {
|
||
description: `### fromCamelCase
|
||
|
||
Converts a string from camelcase.
|
||
|
||
Use \`String.replace()\` to remove underscores, hyphens, and spaces and convert words to camelcase.
|
||
Omit the second argument to use a default \`separator\` of \`_\`.
|
||
|
||
`,
|
||
comments: [`// 'some database field name'`,`// 'some-label-that-needs-to-be-camelized'`,`// 'some_javascript_property'`],
|
||
hash: '79a46435d7d7d46f08097a8442a660a40a931ded762be0741cb37f760ba774ea'
|
||
},
|
||
functionName : {
|
||
description: `### functionName
|
||
|
||
Logs the name of a function.
|
||
|
||
Use \`console.debug()\` and the \`name\` property of the passed method to log the method's name to the \`debug\` channel of the console.
|
||
|
||
`,
|
||
comments: [`// max (logged in debug channel of console)`],
|
||
hash: 'a135f158877f9a78e244205b63291b3b0fbba2954c467d3f8de9f7d220c6e6f6'
|
||
},
|
||
functions : {
|
||
description: `### functions
|
||
|
||
Returns an array of function property names from own (and optionally inherited) enumerable properties of an object.
|
||
|
||
Use \`Object.keys(obj)\` to iterate over the object's own properties.
|
||
If \`inherited\` is \`true\`, use \`Object.get.PrototypeOf(obj)\` to also get the object's inherited properties.
|
||
Use \`Array.filter()\` to keep only those properties that are functions.
|
||
Omit the second argument, \`inherited\`, to not include inherited properties by default.
|
||
|
||
`,
|
||
comments: [`// ['a', 'b']`,`// ['a', 'b', 'c']`],
|
||
hash: '4fd8a0093a5a9e04baa8928e1f35f53d80d52281169b2e3ded3efa4f5c0a4dd1'
|
||
},
|
||
gcd : {
|
||
description: `### gcd
|
||
|
||
Calculates the greatest common divisor between two or more numbers/arrays.
|
||
|
||
The inner \`_gcd\` function uses recursion.
|
||
Base case is when \`y\` equals \`0\`. In this case, return \`x\`.
|
||
Otherwise, return the GCD of \`y\` and the remainder of the division \`x/y\`.
|
||
|
||
`,
|
||
comments: [`// 4`,`// 4`],
|
||
hash: 'a089cfa14c8316d2604567eeabb660394eaa447b3b55f8877d2bffd0e74ba8e8'
|
||
},
|
||
geometricProgression : {
|
||
description: `### geometricProgression
|
||
|
||
Initializes an array containing the numbers in the specified range where \`start\` and \`end\` are inclusive and the ratio between two terms is \`step\`.
|
||
Returns an error if \`step\` equals \`1\`.
|
||
|
||
Use \`Array.from()\`, \`Math.log()\` and \`Math.floor()\` to create an array of the desired length, \`Array.map()\` to fill with the desired values in a range.
|
||
Omit the second argument, \`start\`, to use a default value of \`1\`.
|
||
Omit the third argument, \`step\`, to use a default value of \`2\`.
|
||
|
||
`,
|
||
comments: [`// [1, 2, 4, 8, 16, 32, 64, 128, 256]`,`// [3, 6, 12, 24, 48, 96, 192]`,`// [1, 4, 16, 64, 256]`],
|
||
hash: '3c64dfb3dad29e0d4f87ec7d6bb2448170342db36f2e81682c8ca37eb6cecce9'
|
||
},
|
||
get : {
|
||
description: `### get
|
||
|
||
Retrieve a set of properties indicated by the given selectors from an object.
|
||
|
||
Use \`Array.map()\` for each selector, \`String.replace()\` to replace square brackets with dots, \`String.split('.')\` to split each selector, \`Array.filter()\` to remove empty values and \`Array.reduce()\` to get the value indicated by it.
|
||
|
||
`,
|
||
comments: [`// ['val to select', 1, 'test']`],
|
||
hash: 'a76e1d772d144839c1088cc824ffbeab13d4d7eca49f2d7111d17ab93e0b85a3'
|
||
},
|
||
getColonTimeFromDate : {
|
||
description: `### getColonTimeFromDate
|
||
|
||
Returns a string of the form \`HH:MM:SS\` from a \`Date\` object.
|
||
|
||
Use \`Date.toString()\` and \`String.slice()\` to get the \`HH:MM:SS\` part of a given \`Date\` object.
|
||
|
||
`,
|
||
comments: [`// "08:38:00"`],
|
||
hash: 'd209a5811488f5c44f843ac7cadeaf958c31c10822b9e52e0ad89f44f89f1fb5'
|
||
},
|
||
getDaysDiffBetweenDates : {
|
||
description: `### getDaysDiffBetweenDates
|
||
|
||
Returns the difference (in days) between two dates.
|
||
|
||
Calculate the difference (in days) between two \`Date\` objects.
|
||
|
||
`,
|
||
comments: [`// 9`],
|
||
hash: 'bf00fb96be9d3c6835cab80a49fdb006ac53c00a80c412f5a83d72d0a3c8cb71'
|
||
},
|
||
getMeridiemSuffixOfInteger : {
|
||
description: `### getMeridiemSuffixOfInteger
|
||
|
||
Converts an integer to a suffixed string, adding \`am\` or \`pm\` based on its value.
|
||
|
||
Use the modulo operator (\`%\`) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
|
||
|
||
`,
|
||
comments: [`// "12am"`,`// "11am"`,`// "1pm"`,`// "1pm"`],
|
||
hash: '57e75c7e7077a1a02e0c1a7805f80ccd8b70ab2cb01c1e0934b8b421546e9724'
|
||
},
|
||
getScrollPosition : {
|
||
description: `### getScrollPosition
|
||
|
||
Returns the scroll position of the current page.
|
||
|
||
Use \`pageXOffset\` and \`pageYOffset\` if they are defined, otherwise \`scrollLeft\` and \`scrollTop\`.
|
||
You can omit \`el\` to use a default value of \`window\`.
|
||
|
||
`,
|
||
comments: [`// {x: 0, y: 200}`],
|
||
hash: '56cb5f9d6742b38ade4e43014543721fb521fee32db7c8a0b3e845fd9acb9d74'
|
||
},
|
||
getStyle : {
|
||
description: `### getStyle
|
||
|
||
Returns the value of a CSS rule for the specified element.
|
||
|
||
Use \`Window.getComputedStyle()\` to get the value of the CSS rule for the specified element.
|
||
|
||
`,
|
||
comments: [`// '16px'`],
|
||
hash: '9ca322f9a53d4e35584d18738174cdfd5b745747cdfadc9dbe4ab7492e79b56a'
|
||
},
|
||
getType : {
|
||
description: `### getType
|
||
|
||
Returns the native type of a value.
|
||
|
||
Returns lowercased constructor name of value, \`"undefined"\` or \`"null"\` if value is \`undefined\` or \`null\`.
|
||
|
||
`,
|
||
comments: [`// 'set'`],
|
||
hash: '70f912b7b6050a1e45db91e52108f955be199e67bc418e44350ca75dbc95fa2b'
|
||
},
|
||
getURLParameters : {
|
||
description: `### getURLParameters
|
||
|
||
Returns an object containing the parameters of the current URL.
|
||
|
||
Use \`String.match()\` with an appropriate regular expression to get all key-value pairs, \`Array.reduce()\` to map and combine them into a single object.
|
||
Pass \`location.search\` as the argument to apply to the current \`url\`.
|
||
|
||
`,
|
||
comments: [`//url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}`,`// {}`],
|
||
hash: '1ff87cb26f50c7134e7a0d4fb3a3fe46ee04880fecaa88da8c8627f1c3fbd5c9'
|
||
},
|
||
groupBy : {
|
||
description: `### groupBy
|
||
|
||
Groups the elements of an array based on the given function.
|
||
|
||
Use \`Array.map()\` to map the values of an array to a function or property name.
|
||
Use \`Array.reduce()\` to create an object, where the keys are produced from the mapped results.
|
||
|
||
`,
|
||
comments: [`// {4: [4.2], 6: [6.1, 6.3]}`,`// {3: ['one', 'two'], 5: ['three']}`],
|
||
hash: 'e51bce61fec83f5e1ed2eff4afedddff349bcc84dc3fee6d1dd51bc6f6e4f6c9'
|
||
},
|
||
hammingDistance : {
|
||
description: `### hammingDistance
|
||
|
||
Calculates the Hamming distance between two values.
|
||
|
||
Use XOR operator (\`^\`) to find the bit difference between the two numbers, convert to a binary string using \`toString(2)\`.
|
||
Count and return the number of \`1\`s in the string, using \`match(/1/g)\`.
|
||
|
||
`,
|
||
comments: [`// 1`],
|
||
hash: '98740141438317c0188fbdc9e95b4d4d6d472b92a0f42e7632d8ee9739a81d1f'
|
||
},
|
||
hasClass : {
|
||
description: `### hasClass
|
||
|
||
Returns \`true\` if the element has the specified class, \`false\` otherwise.
|
||
|
||
Use \`element.classList.contains()\` to check if the element has the specified class.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '1b702b5ad1d572d8244d3e76165641fafc84234f54f33f56c36e4c4a8a63b842'
|
||
},
|
||
hasFlags : {
|
||
description: `### hasFlags
|
||
|
||
Check if the current process's arguments contain the specified flags.
|
||
|
||
Use \`Array.every()\` and \`Array.includes()\` to check if \`process.argv\` contains all the specified flags.
|
||
Use a regular expression to test if the specified flags are prefixed with \`-\` or \`--\` and prefix them accordingly.
|
||
|
||
`,
|
||
comments: [`// node myScript.js -s --test --cool=true`,`// true`,`// true`,`// false`],
|
||
hash: '964cfade8a9134232f5d0be2c7826d49735467afb15f43ce472b00cffc0eb703'
|
||
},
|
||
hashBrowser : {
|
||
description: `### hashBrowser
|
||
|
||
Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.
|
||
|
||
Use the [SubtleCrypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) API to create a hash for the given value.
|
||
|
||
`,
|
||
comments: [`//en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.`,`//developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) API to create a hash for the given value.`,`// '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'`],
|
||
hash: '5023bba7071042ed934cffc9c7c10879e1d83159d667d0f7cbd02a7b6563a59c'
|
||
},
|
||
hashNode : {
|
||
description: `### hashNode
|
||
|
||
Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.
|
||
|
||
Use \`crypto\` API to create a hash for the given value.
|
||
|
||
`,
|
||
comments: [`//en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.`,`// '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'`],
|
||
hash: 'e50f540cf0fa0cfab53b5fd6d6db5c75458c9c532635530adcfb6296929e5815'
|
||
},
|
||
head : {
|
||
description: `### head
|
||
|
||
Returns the head of a list.
|
||
|
||
Use \`arr[0]\` to return the first element of the passed array.
|
||
|
||
`,
|
||
comments: [`// 1`],
|
||
hash: '6a9d9363557cd7b6f2da6e75ce00ad391ca43572f9ba517a0da1cc613bfd724b'
|
||
},
|
||
hexToRGB : {
|
||
description: `### hexToRGB
|
||
|
||
Converts a color code to a \`rgb()\` or \`rgba()\` string if alpha value is provided.
|
||
|
||
Use bitwise right-shift operator and mask bits with \`&\` (and) operator to convert a hexadecimal color code (with or without prefixed with \`#\`) to a string with the RGB values. If it's 3-digit color code, first convert to 6-digit version. If an alpha value is provided alongside 6-digit hex, give \`rgba()\` string in return.
|
||
|
||
`,
|
||
comments: [`// 'rgba(39, 174, 96, 255)'`,`// 'rgb(39, 174, 96)'`,`// 'rgb(255, 255, 255)'`],
|
||
hash: '31a0efd8c6843e9140fe0d3fa587b51f6b42dd5a69d0290df3aca1740cc0851a'
|
||
},
|
||
hide : {
|
||
description: `### hide
|
||
|
||
Hides all the elements specified.
|
||
|
||
Use the spread operator (\`...\`) and \`Array.forEach()\` to apply \`display: none\` to each element specified.
|
||
|
||
`,
|
||
comments: [`// Hides all <img> elements on the page`],
|
||
hash: 'f4b802aa0800b92466ce3edfc37c72207ef749cf9cfab92db2d009c15a0e116c'
|
||
},
|
||
httpGet : {
|
||
description: `### httpGet
|
||
|
||
Makes a \`GET\` request to the passed URL.
|
||
|
||
Use [\`XMLHttpRequest\`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) web api to make a \`get\` request to the given \`url\`.
|
||
Handle the \`onload\` event, by calling the given \`callback\` the \`responseText\`.
|
||
Handle the \`onerror\` event, by running the provided \`err\` function.
|
||
Omit the third argument, \`err\`, to log errors to the console's \`error\` stream by default.
|
||
|
||
`,
|
||
comments: [`//developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) web api to make a \`get\` request to the given \`url\`.`,`//jsonplaceholder.typicode.com/posts/1',`],
|
||
hash: '3b30d0fbb1232a8e297ddf3d47f6095cc07f42f39a76f1c9123f387d10e19ceb'
|
||
},
|
||
httpPost : {
|
||
description: `### httpPost
|
||
|
||
Makes a \`POST\` request to the passed URL.
|
||
|
||
Use [\`XMLHttpRequest\`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) web api to make a \`post\` request to the given \`url\`.
|
||
Set the value of an \`HTTP\` request header with \`setRequestHeader\` method.
|
||
Handle the \`onload\` event, by calling the given \`callback\` the \`responseText\`.
|
||
Handle the \`onerror\` event, by running the provided \`err\` function.
|
||
Omit the third argument, \`data\`, to send no data to the provided \`url\`.
|
||
Omit the fourth argument, \`err\`, to log errors to the console's \`error\` stream by default.
|
||
|
||
`,
|
||
comments: [`//developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) web api to make a \`post\` request to the given \`url\`.`,`//jsonplaceholder.typicode.com/posts',`,`//jsonplaceholder.typicode.com/posts',`,`//does not send a body`],
|
||
hash: '74d7310fb6ddda6c02ef698853dd48ae5fc44096f17805f974d407b36f6e6ec8'
|
||
},
|
||
httpsRedirect : {
|
||
description: `### httpsRedirect
|
||
|
||
Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history.
|
||
|
||
Use \`location.protocol\` to get the protocol currently being used. If it's not HTTPS, use \`location.replace()\` to replace the existing page with the HTTPS version of the page. Use \`location.href\` to get the full address, split it with \`String.split()\` and remove the protocol part of the URL.
|
||
|
||
`,
|
||
comments: [`//' + location.href.split('//')[1]);`,`// If you are on http://mydomain.com, you are redirected to https://mydomain.com`],
|
||
hash: '49f962c9be2cfe0e5e73b465d418497571988fe60b87c00fd0fff15a3666afa5'
|
||
},
|
||
indexOfAll : {
|
||
description: `### indexOfAll
|
||
|
||
Returns all indices of \`val\` in an array. If \`val\` never occurs, returns \`[]\`.
|
||
|
||
Use \`Array.forEach()\` to loop over elements and \`Array.push()\` to store indices for matching elements.
|
||
Return the array of indices.
|
||
|
||
`,
|
||
comments: [`// [0,3]`,`// []`],
|
||
hash: '1b660ea5b19eb7bed6fbb637697952e4fc7ea8fcf85493dc9c658626e3d546e8'
|
||
},
|
||
initial : {
|
||
description: `### initial
|
||
|
||
Returns all the elements of an array except the last one.
|
||
|
||
Use \`arr.slice(0,-1)\` to return all but the last element of the array.
|
||
|
||
`,
|
||
comments: [`// [1,2]`],
|
||
hash: '0b2c9f2799ea49dca3bc13b3346b2fb51171f4db8ec5a49860fd2af34ae30c76'
|
||
},
|
||
initialize2DArray : {
|
||
description: `### initialize2DArray
|
||
|
||
Initializes a 2D array of given width and height and value.
|
||
|
||
Use \`Array.map()\` to generate h rows where each is a new array of size w initialize with value. If the value is not provided, default to \`null\`.
|
||
|
||
`,
|
||
comments: [`// [[0,0], [0,0]]`],
|
||
hash: '613cfa641222fa5c1493abc3dd2315bcbec201b2ac763b780590d63b2a853c51'
|
||
},
|
||
initializeArrayWithRange : {
|
||
description: `### initializeArrayWithRange
|
||
|
||
Initializes an array containing the numbers in the specified range where \`start\` and \`end\` are inclusive with their common difference \`step\`.
|
||
|
||
Use \`Array.from(Math.ceil((end+1-start)/step))\` to create an array of the desired length(the amounts of elements is equal to \`(end-start)/step\` or \`(end+1-start)/step\` for inclusive end), \`Array.map()\` to fill with the desired values in a range.
|
||
You can omit \`start\` to use a default value of \`0\`.
|
||
You can omit \`step\` to use a default value of \`1\`.
|
||
|
||
`,
|
||
comments: [`// [0,1,2,3,4,5]`,`// [3,4,5,6,7]`,`// [0,2,4,6,8]`],
|
||
hash: '249a523afbbc8d2e49977526c23e7aab22624ed3b70877d796ae5c43900683ca'
|
||
},
|
||
initializeArrayWithRangeRight : {
|
||
description: `### initializeArrayWithRangeRight
|
||
|
||
Initializes an array containing the numbers in the specified range (in reverse) where \`start\` and \`end\` are inclusive with their common difference \`step\`.
|
||
|
||
Use \`Array.from(Math.ceil((end+1-start)/step))\` to create an array of the desired length(the amounts of elements is equal to \`(end-start)/step\` or \`(end+1-start)/step\` for inclusive end), \`Array.map()\` to fill with the desired values in a range.
|
||
You can omit \`start\` to use a default value of \`0\`.
|
||
You can omit \`step\` to use a default value of \`1\`.
|
||
|
||
`,
|
||
comments: [`// [5,4,3,2,1,0]`,`// [7,6,5,4,3]`,`// [8,6,4,2,0]`],
|
||
hash: '86eaa064d6dd675dd20e075600a230473fa8a827708273f8184467ad8a27e347'
|
||
},
|
||
initializeArrayWithValues : {
|
||
description: `### initializeArrayWithValues
|
||
|
||
Initializes and fills an array with the specified values.
|
||
|
||
Use \`Array(n)\` to create an array of the desired length, \`fill(v)\` to fill it with the desired values.
|
||
You can omit \`val\` to use a default value of \`0\`.
|
||
|
||
`,
|
||
comments: [`// [2,2,2,2,2]`],
|
||
hash: '87e1684c5acda0f9870b554e94960b5eabf5daf4ca6904b7bad9fe9fd3c930d4'
|
||
},
|
||
inRange : {
|
||
description: `### inRange
|
||
|
||
Checks if the given number falls within the given range.
|
||
|
||
Use arithmetic comparison to check if the given number is in the specified range.
|
||
If the second parameter, \`end\`, is not specified, the range is considered to be from \`0\` to \`start\`.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// false`,`// false`],
|
||
hash: 'e3faba5899f7839bdb02e5a6a40ad4ce9b1d6de08972887eb388e27b0e6f9211'
|
||
},
|
||
intersection : {
|
||
description: `### intersection
|
||
|
||
Returns a list of elements that exist in both arrays.
|
||
|
||
Create a \`Set\` from \`b\`, then use \`Array.filter()\` on \`a\` to only keep values contained in \`b\`.
|
||
|
||
`,
|
||
comments: [`// [2,3]`],
|
||
hash: 'a47f3624bb684bedc89b5906a63186d30147515475f4d8e706738bc2b15e394b'
|
||
},
|
||
intersectionBy : {
|
||
description: `### intersectionBy
|
||
|
||
Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both.
|
||
|
||
Create a \`Set\` by applying \`fn\` to all elements in \`b\`, then use \`Array.filter()\` on \`a\` to only keep elements, which produce values contained in \`b\` when \`fn\` is applied to them.
|
||
|
||
`,
|
||
comments: [`// [2.1]`],
|
||
hash: '1e556ba22570e0d72e2b37d180f15728954a948f02b1dc7ca5151ee43c74831b'
|
||
},
|
||
intersectionWith : {
|
||
description: `### intersectionWith
|
||
|
||
Returns a list of elements that exist in both arrays, using a provided comparator function.
|
||
|
||
Use \`Array.filter()\` and \`Array.findIndex()\` in combination with the provided comparator to determine intersecting values.
|
||
|
||
`,
|
||
comments: [`// [1.5, 3, 0]`],
|
||
hash: '5ff22be7dc2c54131b58eae93beb3e6057a4abb186295c269f1fa2736aa817da'
|
||
},
|
||
invertKeyValues : {
|
||
description: `### invertKeyValues
|
||
|
||
Inverts the key-value pairs of an object, without mutating it. The corresponding inverted value of each inverted key is an array of keys responsible for generating the inverted value. If a function is supplied, it is applied to each inverted key.
|
||
|
||
Use \`Object.keys()\` and \`Array.reduce()\` to invert the key-value pairs of an object and apply the function provided (if any).
|
||
Omit the second argument, \`fn\`, to get the inverted keys without applying a function to them.
|
||
|
||
`,
|
||
comments: [`// { 1: [ 'a', 'c' ], 2: [ 'b' ] }`,`// { group1: [ 'a', 'c' ], group2: [ 'b' ] }`],
|
||
hash: '07023e56f241ca10160d7d3472bbf8d85e45dfc511015cb4ac558709bc4049ce'
|
||
},
|
||
is : {
|
||
description: `### is
|
||
|
||
Checks if the provided value is of the specified type (doesn't work with literals).
|
||
|
||
Use the \`instanceof\` operator to check if the provided value is of the specified \`type\`.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// true`,`// true`,`// true`,`// true`,`// true`,`// false`,`// true`,`// false`,`// true`,`// false`,`// true`],
|
||
hash: '92478f7c1865c4bd82d22c6f941f8f1de5124ed91f0cb46b32bf4cc8b81050fe'
|
||
},
|
||
isAbsoluteURL : {
|
||
description: `### isAbsoluteURL
|
||
|
||
Returns \`true\` if the given string is an absolute URL, \`false\` otherwise.
|
||
|
||
Use a regular expression to test if the string is an absolute URL.
|
||
|
||
`,
|
||
comments: [`//google.com'); // true`,`//www.myserver.net'); // true`,`// false`],
|
||
hash: 'a1c0b0ccf3608b21f23e16d72172d50d7b8eddd6575417553b24ad12fdce0984'
|
||
},
|
||
isArrayLike : {
|
||
description: `### isArrayLike
|
||
|
||
Checks if the provided argument is array-like (i.e. is iterable).
|
||
|
||
Use the spread operator (\`...\`) to check if the provided argument is iterable inside a \`try... catch\` block and the comma operator (\`,\`) to return the appropriate value.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// false`],
|
||
hash: '5fa02581df99c788cb1eada4e3bc53cd76f5b78e21ea0f67e28b14965a5fb513'
|
||
},
|
||
isBoolean : {
|
||
description: `### isBoolean
|
||
|
||
Checks if the given argument is a native boolean element.
|
||
|
||
Use \`typeof\` to check if a value is classified as a boolean primitive.
|
||
|
||
`,
|
||
comments: [`// false`,`// true`],
|
||
hash: '939b9a43fb54f623ae441983aa890dfed498d21a198d13587a9a5c82b2470630'
|
||
},
|
||
isDivisible : {
|
||
description: `### isDivisible
|
||
|
||
Checks if the first numeric argument is divisible by the second one.
|
||
|
||
Use the modulo operator (\`%\`) to check if the remainder is equal to \`0\`.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '567ff4e71c4ad30ebb365fd9b91a54b5a1b46a2d832b7f6947ed06da94b4622d'
|
||
},
|
||
isEmpty : {
|
||
description: `### isEmpty
|
||
|
||
Returns true if the a value is an empty object, collection, map or set, has no enumerable properties or is any type that is not considered a collection.
|
||
|
||
Check if the provided value is \`null\` or if its \`length\` is equal to \`0\`.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// true`,`// true`,`// true`,`// false`,`// false`,`// false`,`// true - type is not considered a collection`,`// true - type is not considered a collection`],
|
||
hash: '243117a13cd98f68b115e68906166c518101a5a59eb18b39b677a355853c6c0e'
|
||
},
|
||
isEven : {
|
||
description: `### isEven
|
||
|
||
Returns \`true\` if the given number is even, \`false\` otherwise.
|
||
|
||
Checks whether a number is odd or even using the modulo (\`%\`) operator.
|
||
Returns \`true\` if the number is even, \`false\` if the number is odd.
|
||
|
||
`,
|
||
comments: [`// false`],
|
||
hash: 'b6b6b6acedfee36a382482eec099ae2ae557b57b9247bc50388a28b6fffc870c'
|
||
},
|
||
isFunction : {
|
||
description: `### isFunction
|
||
|
||
Checks if the given argument is a function.
|
||
|
||
Use \`typeof\` to check if a value is classified as a function primitive.
|
||
|
||
`,
|
||
comments: [`// false`,`// true`],
|
||
hash: '608f4b36d061a98a0f8203ba3cecb48f87ccc6f7720fd5449e34b576f98aaecf'
|
||
},
|
||
isLowerCase : {
|
||
description: `### isLowerCase
|
||
|
||
Checks if a string is lower case.
|
||
|
||
Convert the given string to lower case, using \`String.toLowerCase()\` and compare it to the original.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// false`],
|
||
hash: 'db0ceaf0fe1e662750aabd1bd54032b17c471efc2511a120354cccc1f7d0808d'
|
||
},
|
||
isNil : {
|
||
description: `### isNil
|
||
|
||
Returns \`true\` if the specified value is \`null\` or \`undefined\`, \`false\` otherwise.
|
||
|
||
Use the strict equality operator to check if the value and of \`val\` are equal to \`null\` or \`undefined\`.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`],
|
||
hash: '6098b98799252bd8297351aaae52530f6d70454e9bc00491d47e401a28e92e11'
|
||
},
|
||
isNull : {
|
||
description: `### isNull
|
||
|
||
Returns \`true\` if the specified value is \`null\`, \`false\` otherwise.
|
||
|
||
Use the strict equality operator to check if the value and of \`val\` are equal to \`null\`.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '3286793e1526d264a82f61f3ea3ec24be21f735e6df3a4349a5d124de52f8096'
|
||
},
|
||
isNumber : {
|
||
description: `### isNumber
|
||
|
||
Checks if the given argument is a number.
|
||
|
||
Use \`typeof\` to check if a value is classified as a number primitive.
|
||
|
||
`,
|
||
comments: [`// false`,`// true`],
|
||
hash: '319ed6fe8bd0ac2265d84e02a9cf3cf9245e52666e3d1f4d1c68060d6d222a15'
|
||
},
|
||
isObject : {
|
||
description: `### isObject
|
||
|
||
Returns a boolean determining if the passed value is an object or not.
|
||
|
||
Uses the \`Object\` constructor to create an object wrapper for the given value.
|
||
If the value is \`null\` or \`undefined\`, create and return an empty object. Οtherwise, return an object of a type that corresponds to the given value.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// true`,`// true`,`// true`,`// false`],
|
||
hash: '6bbd64bdaada44df70084acbe3aebe1057ae3cb63d3c397272a88069c27023f6'
|
||
},
|
||
isObjectLike : {
|
||
description: `### isObjectLike
|
||
|
||
Checks if a value is object-like.
|
||
|
||
Check if the provided value is not \`null\` and its \`typeof\` is equal to \`'object'\`.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// false`,`// false`],
|
||
hash: 'c54f1c3d860b85ead765941dc29927c814df798be381d4b7af15145aa5248866'
|
||
},
|
||
isPlainObject : {
|
||
description: `### isPlainObject
|
||
|
||
Checks if the provided value is an object created by the Object constructor.
|
||
|
||
Check if the provided value is truthy, use \`typeof\` to check if it is an object and \`Object.constructor\` to make sure the constructor is equal to \`Object\`.
|
||
|
||
`,
|
||
comments: [`// true`,`// false`],
|
||
hash: '145da6b8fa6d399c9d53c1a49627a9aa12588ba08f22e8c0237663cdd29a3540'
|
||
},
|
||
isPrime : {
|
||
description: `### isPrime
|
||
|
||
Checks if the provided integer is a prime number.
|
||
|
||
Check numbers from \`2\` to the square root of the given number.
|
||
Return \`false\` if any of them divides the given number, else return \`true\`, unless the number is less than \`2\`.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '8f2dc25121cc870f19c7e4614d1e2bfb80f69abb9f940e34506dd282d8b8b64f'
|
||
},
|
||
isPrimitive : {
|
||
description: `### isPrimitive
|
||
|
||
Returns a boolean determining if the passed value is primitive or not.
|
||
|
||
Use \`Array.includes()\` on an array of type strings which are not primitive,
|
||
supplying the type using \`typeof\`.
|
||
Since \`typeof null\` evaluates to \`'object'\`, it needs to be directly compared.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// true`,`// true`,`// true`,`// false`],
|
||
hash: '0b87a6344a40ec2e47acaed9b601441386cf18da96a491a99f087a9aa8ca6dd7'
|
||
},
|
||
isPromiseLike : {
|
||
description: `### isPromiseLike
|
||
|
||
Returns \`true\` if an object looks like a [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), \`false\` otherwise.
|
||
|
||
Check if the object is not \`null\`, its \`typeof\` matches either \`object\` or \`function\` and if it has a \`.then\` property, which is also a \`function\`.
|
||
|
||
`,
|
||
comments: [`//developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), \`false\` otherwise.`,`// true`,`// false`,`// false`],
|
||
hash: '42a7fea8a7f6348aad1a916f980af5c14d29da68748242340ff7298305117657'
|
||
},
|
||
isSorted : {
|
||
description: `### isSorted
|
||
|
||
Returns \`1\` if the array is sorted in ascending order, \`-1\` if it is sorted in descending order or \`0\` if it is not sorted.
|
||
|
||
Calculate the ordering \`direction\` for the first two elements.
|
||
Use \`Object.entries()\` to loop over array objects and compare them in pairs.
|
||
Return \`0\` if the \`direction\` changes or the \`direction\` if the last element is reached.
|
||
|
||
`,
|
||
comments: [`// 1`,`// -1`,`// 0`],
|
||
hash: '13cd1ca2617236845d0bd97d5d22aa9a3619c1fa97eb8cdab7387580c7202749'
|
||
},
|
||
isString : {
|
||
description: `### isString
|
||
|
||
Checks if the given argument is a string.
|
||
|
||
Use \`typeof\` to check if a value is classified as a string primitive.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '950b5898c552fd198d97adc855e480c5e0a2e32acd0404d7c9b49bbe09f34394'
|
||
},
|
||
isSymbol : {
|
||
description: `### isSymbol
|
||
|
||
Checks if the given argument is a symbol.
|
||
|
||
Use \`typeof\` to check if a value is classified as a symbol primitive.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '772115bcf4dc1edd0493e55b422c0d5d35cd4719133840bf6d692e6d364df12f'
|
||
},
|
||
isTravisCI : {
|
||
description: `### isTravisCI
|
||
|
||
Checks if the current environment is [Travis CI](https://travis-ci.org/).
|
||
|
||
Checks if the current environment has the \`TRAVIS\` and \`CI\` environment variables ([reference](https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables)).
|
||
|
||
`,
|
||
comments: [`//travis-ci.org/).`,`//docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables)).`,`// true (if code is running on Travis CI)`],
|
||
hash: 'c9e8be3686e292a4db56f8f6068ed75705b3260373689a10b57401703581f5cf'
|
||
},
|
||
isUndefined : {
|
||
description: `### isUndefined
|
||
|
||
Returns \`true\` if the specified value is \`undefined\`, \`false\` otherwise.
|
||
|
||
Use the strict equality operator to check if the value and of \`val\` are equal to \`undefined\`.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '2eeeb674c5f4947224fb065e5a1fa0b0adbbefd9b7fab99190cc9a4b65bab724'
|
||
},
|
||
isUpperCase : {
|
||
description: `### isUpperCase
|
||
|
||
Checks if a string is upper case.
|
||
|
||
Convert the given string to upper case, using \`String.toUpperCase()\` and compare it to the original.
|
||
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// false`],
|
||
hash: '3450e2509a1e6beb102b98b987ca73924d55e7314dbddbbbd8acfdb147fdbecd'
|
||
},
|
||
isValidJSON : {
|
||
description: `### isValidJSON
|
||
|
||
Checks if the provided argument is a valid JSON.
|
||
|
||
Use \`JSON.parse()\` and a \`try... catch\` block to check if the provided argument is a valid JSON.
|
||
|
||
`,
|
||
comments: [`// true`,`// false`,`// true`],
|
||
hash: 'a0ce043d4ed321c92f30bba8fd9e27270581e0bfae327e6efe3e637cc51700d5'
|
||
},
|
||
join : {
|
||
description: `### join
|
||
|
||
Joins all elements of an array into a string and returns this string. Uses a separator and an end separator.
|
||
|
||
Use \`Array.reduce()\` to combine elements into a string.
|
||
Omit the second argument, \`separator\`, to use a default separator of \`','\`.
|
||
Omit the third argument, \`end\`, to use the same value as \`separator\` by default.
|
||
|
||
`,
|
||
comments: [`// "pen,pineapple,apple&pen"`,`// "pen,pineapple,apple,pen"`,`// "pen,pineapple,apple,pen"`],
|
||
hash: '87811928e680a995933e2bf0020174e9983eebcfcc1a26b7eb5d56c643e441be'
|
||
},
|
||
JSONToFile : {
|
||
description: `### JSONToFile
|
||
|
||
Writes a JSON object to a file.
|
||
|
||
Use \`fs.writeFile()\`, template literals and \`JSON.stringify()\` to write a \`json\` object to a \`.json\` file.
|
||
|
||
`,
|
||
comments: [`// writes the object to 'testJsonFile.json'`],
|
||
hash: 'a44f1723a47ee41237a23e791519b39cf3ac206a3a2b79430bd023a3af8e44ef'
|
||
},
|
||
last : {
|
||
description: `### last
|
||
|
||
Returns the last element in an array.
|
||
|
||
Use \`arr.length - 1\` to compute the index of the last element of the given array and returning it.
|
||
|
||
`,
|
||
comments: [`// 3`],
|
||
hash: '3439302a2366ff96c558f451a0a492524fb05e11bfbca39629400b3656ae2aff'
|
||
},
|
||
lcm : {
|
||
description: `### lcm
|
||
|
||
Returns the least common multiple of two or more numbers.
|
||
|
||
Use the greatest common divisor (GCD) formula and the fact that \`lcm(x,y) = x * y / gcd(x,y)\` to determine the least common multiple.
|
||
The GCD formula uses recursion.
|
||
|
||
`,
|
||
comments: [`// 84`,`// 60`],
|
||
hash: '138716f0d371c6a5f6774c1a6da35b2e8187cc6dab5f9d6cdb5c76327318d210'
|
||
},
|
||
longestItem : {
|
||
description: `### longestItem
|
||
|
||
Takes any number of iterable objects or objects with a \`length\` property and returns the longest one.
|
||
|
||
Use \`Array.sort()\` to sort all arguments by \`length\`, return the first (longest) one.
|
||
|
||
`,
|
||
comments: [`// 'testcase'`,`// 'abc'`,`// 'abcd'`,`// [1, 2, 3, 4, 5]`,`// 'foobar'`],
|
||
hash: 'e9686ac4809ee0049f65662bd446a208493eff7ac31cff7f5424b0252e0887aa'
|
||
},
|
||
lowercaseKeys : {
|
||
description: `### lowercaseKeys
|
||
|
||
Creates a new object from the specified object, where all the keys are in lowercase.
|
||
|
||
Use \`Object.keys()\` and \`Array.reduce()\` to create a new object from the specified object.
|
||
Convert each key in the original object to lowercase, using \`String.toLowerCase()\`.
|
||
|
||
`,
|
||
comments: [`// {name: 'Adam', surname: 'Smith'};`],
|
||
hash: '814caed29be26ad7b58b3bc7c9990565211abf9d6edc81a431fc050ee276cc23'
|
||
},
|
||
luhnCheck : {
|
||
description: `### luhnCheck
|
||
|
||
Implementation of the [Luhn Algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc.
|
||
|
||
Use \`String.split('')\`, \`Array.reverse()\` and \`Array.map()\` in combination with \`parseInt()\` to obtain an array of digits.
|
||
Use \`Array.splice(0,1)\` to obtain the last digit.
|
||
Use \`Array.reduce()\` to implement the Luhn Algorithm.
|
||
Return \`true\` if \`sum\` is divisible by \`10\`, \`false\` otherwise.
|
||
|
||
|
||
`,
|
||
comments: [`//en.wikipedia.org/wiki/Luhn_algorithm) used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc.`,`// true`,`// false`,`// false`],
|
||
hash: '5c4099ce67b4fe29d681976195a0b73d93a7d5030519dbb2faab8cb0a9c506dc'
|
||
},
|
||
mapKeys : {
|
||
description: `### mapKeys
|
||
|
||
Creates an object with keys generated by running the provided function for each key and the same values as the provided object.
|
||
|
||
Use \`Object.keys(obj)\` to iterate over the object's keys.
|
||
Use \`Array.reduce()\` to create a new object with the same values and mapped keys using \`fn\`.
|
||
|
||
`,
|
||
comments: [`// { a1: 1, b2: 2 }`],
|
||
hash: '057377a13df66b41ba55e565c089c2e5555c8cd11e8e809f6026cce9393c79c3'
|
||
},
|
||
mapObject : {
|
||
description: `### mapObject
|
||
|
||
Maps the values of an array to an object using a function, where the key-value pairs consist of the original value as the key and the mapped value.
|
||
|
||
Use an anonymous inner function scope to declare an undefined memory space, using closures to store a return value. Use a new \`Array\` to store the array with a map of the function over its data set and a comma operator to return a second step, without needing to move from one context to another (due to closures and order of operations).
|
||
|
||
`,
|
||
comments: [`// { 1: 1, 2: 4, 3: 9 }`],
|
||
hash: 'e2cfc281da735e9646736c04e68be072d6beb8e4be9151d1cfb3b4d108a33a3b'
|
||
},
|
||
mapValues : {
|
||
description: `### mapValues
|
||
|
||
Creates an object with the same keys as the provided object and values generated by running the provided function for each value.
|
||
|
||
Use \`Object.keys(obj)\` to iterate over the object's keys.
|
||
Use \`Array.reduce()\` to create a new object with the same keys and mapped values using \`fn\`.
|
||
|
||
`,
|
||
comments: [`// { fred: 40, pebbles: 1 }`],
|
||
hash: 'f5d593346b2ff0fc0924b56db462cb53b991bc8dee71e4d5863ef1cd2c3a686e'
|
||
},
|
||
mask : {
|
||
description: `### mask
|
||
|
||
Replaces all but the last \`num\` of characters with the specified mask character.
|
||
|
||
Use \`String.slice()\` to grab the portion of the characters that need to be masked and use \`String.replace()\` with a regexp to replace every character with the mask character.
|
||
Concatenate the masked characters with the remaining unmasked portion of the string.
|
||
Omit the second argument, \`num\`, to keep a default of \`4\` characters unmasked. If \`num\` is negative, the unmasked characters will be at the start of the string.
|
||
Omit the third argument, \`mask\`, to use a default character of \`'*'\` for the mask.
|
||
|
||
`,
|
||
comments: [`// '******7890'`,`// '*******890'`,`// '$$$$567890'`],
|
||
hash: '7b89d9ce8cb19b762cfd57a005a688d5f82faf29e0e9067fab3f3c8892b41182'
|
||
},
|
||
matches : {
|
||
description: `### matches
|
||
|
||
Compares two objects to determine if the first one contains equivalent property values to the second one.
|
||
|
||
Use \`Object.keys(source)\` to get all the keys of the second object, then \`Array.every()\`, \`Object.hasOwnProperty()\` and strict comparison to determine if all keys exist in the first object and have the same values.
|
||
|
||
`,
|
||
comments: [`// true`,`// false`],
|
||
hash: '6bc4b4501cf025724b14200d9c3952b5f90f95da9dd9c51e9bb67ddee7668caf'
|
||
},
|
||
matchesWith : {
|
||
description: `### matchesWith
|
||
|
||
Compares two objects to determine if the first one contains equivalent property values to the second one, based on a provided function.
|
||
|
||
Use \`Object.keys(source)\` to get all the keys of the second object, then \`Array.every()\`, \`Object.hasOwnProperty()\` and the provided function to determine if all keys exist in the first object and have equivalent values.
|
||
If no function is provided, the values will be compared using the equality operator.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '55f1b19b911497b0590d1477e0756669a9895c5ad780ab178c1388e93b21503f'
|
||
},
|
||
maxBy : {
|
||
description: `### maxBy
|
||
|
||
Returns the maximum value of an array, after mapping each element to a value using the provided function.
|
||
|
||
Use \`Array.map()\` to map each element to the value returned by \`fn\`, \`Math.max()\` to get the maximum value.
|
||
|
||
`,
|
||
comments: [`// 8`,`// 8`],
|
||
hash: 'adaadb4a74c72470bf8e30e24ef1dd2cb0376bbb7204b38364d46b4cf1bf9b17'
|
||
},
|
||
maxN : {
|
||
description: `### maxN
|
||
|
||
Returns the \`n\` maximum elements from the provided array. If \`n\` is greater than or equal to the provided array's length, then return the original array(sorted in descending order).
|
||
|
||
Use \`Array.sort()\` combined with the spread operator (\`...\`) to create a shallow clone of the array and sort it in descending order.
|
||
Use \`Array.slice()\` to get the specified number of elements.
|
||
Omit the second argument, \`n\`, to get a one-element array.
|
||
|
||
`,
|
||
comments: [`// [3]`,`// [3,2]`],
|
||
hash: '9af9c62fb092b800e35b6f32e9a05f4991adf104748e2de690833294800f6ca9'
|
||
},
|
||
median : {
|
||
description: `### median
|
||
|
||
Returns the median of an array of numbers.
|
||
|
||
Find the middle of the array, use \`Array.sort()\` to sort the values.
|
||
Return the number at the midpoint if \`length\` is odd, otherwise the average of the two middle numbers.
|
||
|
||
`,
|
||
comments: [`// 5`],
|
||
hash: '02917777dc6bb9b6f3d7c7677ffadd228ae1b04b5f281ee410fe997f6ffc8b6e'
|
||
},
|
||
memoize : {
|
||
description: `### memoize
|
||
|
||
Returns the memoized (cached) function.
|
||
|
||
Create an empty cache by instantiating a new \`Map\` object.
|
||
Return a function which takes a single argument to be supplied to the memoized function by first checking if the function's output for that specific input value is already cached, or store and return it if not. The \`function\` keyword must be used in order to allow the memoized function to have its \`this\` context changed if necessary.
|
||
Allow access to the \`cache\` by setting it as a property on the returned function.
|
||
|
||
`,
|
||
comments: [`// See the \`anagrams\` snippet.`,`// takes a long time`,`// returns virtually instantly since it's now cached`,`// The cached anagrams map`],
|
||
hash: '90e3a88fc1d6657c0abad7ef8bf1d16d63ad79e0a3b3e3333b8d9113dd71b319'
|
||
},
|
||
merge : {
|
||
description: `### merge
|
||
|
||
Creates a new object from the combination of two or more objects.
|
||
|
||
Use \`Array.reduce()\` combined with \`Object.keys(obj)\` to iterate over all objects and keys.
|
||
Use \`hasOwnProperty()\` and \`Array.concat()\` to append values for keys existing in multiple objects.
|
||
|
||
`,
|
||
comments: [`// { a: [ { x: 2 }, { y: 4 }, { z: 3 } ], b: [ 1, 2, 3 ], c: 'foo' }`],
|
||
hash: '826cc803746ea19eb0fcfe106f0311d42a5ec4eb55ab3cc5d21cbb903b0c8939'
|
||
},
|
||
minBy : {
|
||
description: `### minBy
|
||
|
||
Returns the minimum value of an array, after mapping each element to a value using the provided function.
|
||
|
||
Use \`Array.map()\` to map each element to the value returned by \`fn\`, \`Math.min()\` to get the maximum value.
|
||
|
||
`,
|
||
comments: [`// 2`,`// 2`],
|
||
hash: '79fa8886b81fec87e6f66bca39c1f24e7dbbfc95f3a0f647d84b639f2097de83'
|
||
},
|
||
minN : {
|
||
description: `### minN
|
||
|
||
Returns the \`n\` minimum elements from the provided array. If \`n\` is greater than or equal to the provided array's length, then return the original array(sorted in ascending order).
|
||
|
||
Use \`Array.sort()\` combined with the spread operator (\`...\`) to create a shallow clone of the array and sort it in ascending order.
|
||
Use \`Array.slice()\` to get the specified number of elements.
|
||
Omit the second argument, \`n\`, to get a one-element array.
|
||
|
||
`,
|
||
comments: [`// [1]`,`// [1,2]`],
|
||
hash: '4ee3bf1ab3e37719595ac57d8036d7fd98997b7da40d060c5e5dcb4efbe505e1'
|
||
},
|
||
negate : {
|
||
description: `### negate
|
||
|
||
Negates a predicate function.
|
||
|
||
Take a predicate function and apply the not operator (\`!\`) to it with its arguments.
|
||
|
||
`,
|
||
comments: [`// [ 1, 3, 5 ]`],
|
||
hash: '8938f36bd51423282e19bf1d4547b8a8a1ebf1882abf7ec4e7ff371922e078e0'
|
||
},
|
||
nthArg : {
|
||
description: `### nthArg
|
||
|
||
Creates a function that gets the argument at index \`n\`. If \`n\` is negative, the nth argument from the end is returned.
|
||
|
||
Use \`Array.slice()\` to get the desired argument at index \`n\`.
|
||
|
||
`,
|
||
comments: [`// 3`,`// undefined`,`// 5`],
|
||
hash: 'a460f755fb40d4a37f6d207f1164b1e76c76059143bff4e5dff76e82ba46ec92'
|
||
},
|
||
nthElement : {
|
||
description: `### nthElement
|
||
|
||
Returns the nth element of an array.
|
||
|
||
Use \`Array.slice()\` to get an array containing the nth element at the first place.
|
||
If the index is out of bounds, return \`[]\`.
|
||
Omit the second argument, \`n\`, to get the first element of the array.
|
||
|
||
`,
|
||
comments: [`// 'b'`,`// 'a'`],
|
||
hash: '153905a03572367df0c41880e11216a53be071a133f74815a67b8bcd67eac404'
|
||
},
|
||
objectFromPairs : {
|
||
description: `### objectFromPairs
|
||
|
||
Creates an object from the given key-value pairs.
|
||
|
||
Use \`Array.reduce()\` to create and combine key-value pairs.
|
||
|
||
`,
|
||
comments: [`// {a: 1, b: 2}`],
|
||
hash: 'ab43b5144f2d236fdab194c4522db8d477183a606fbb81da19d68f74913c917c'
|
||
},
|
||
objectToPairs : {
|
||
description: `### objectToPairs
|
||
|
||
Creates an array of key-value pair arrays from an object.
|
||
|
||
Use \`Object.keys()\` and \`Array.map()\` to iterate over the object's keys and produce an array with key-value pairs.
|
||
|
||
`,
|
||
comments: [`// [['a',1],['b',2]]`],
|
||
hash: '9a61320908a1965f5834bc0187be7fb52897f545f03dc62c4dedeb47fcfbaf8b'
|
||
},
|
||
observeMutations : {
|
||
description: `### observeMutations
|
||
|
||
Returns a new MutationObserver and runs the provided callback for each mutation on the specified element.
|
||
|
||
Use a [\`MutationObserver\`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) to observe mutations on the given element.
|
||
Use \`Array.forEach()\` to run the callback for each mutation that is observed.
|
||
Omit the third argument, \`options\`, to use the default [options](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver#MutationObserverInit) (all \`true\`).
|
||
|
||
`,
|
||
comments: [`//developer.mozilla.org/en-US/docs/Web/API/MutationObserver) to observe mutations on the given element.`,`//developer.mozilla.org/en-US/docs/Web/API/MutationObserver#MutationObserverInit) (all \`true\`).`,`// Logs all mutations that happen on the page`,`// Disconnects the observer and stops logging mutations on the page`],
|
||
hash: '9c3846719bfb9316cb340a39f0ce5b85a5bda268515e079d014f28477f236f2f'
|
||
},
|
||
off : {
|
||
description: `### off
|
||
|
||
Removes an event listener from an element.
|
||
|
||
Use \`EventTarget.removeEventListener()\` to remove an event listener from an element.
|
||
Omit the fourth argument \`opts\` to use \`false\` or specify it based on the options used when the event listener was added.
|
||
|
||
`,
|
||
comments: [`// no longer logs '!' upon clicking on the page`],
|
||
hash: '613baa2166459b02d033323f517bd6a646eab362ac6ecb74841757353ac41482'
|
||
},
|
||
omit : {
|
||
description: `### omit
|
||
|
||
Omits the key-value pairs corresponding to the given keys from an object.
|
||
|
||
Use \`Object.keys(obj)\`, \`Array.filter()\` and \`Array.includes()\` to remove the provided keys.
|
||
Use \`Array.reduce()\` to convert the filtered keys back to an object with the corresponding key-value pairs.
|
||
|
||
`,
|
||
comments: [`// { 'a': 1, 'c': 3 }`],
|
||
hash: 'a50a087ca63a6f9d68cb929e3f75545cbed4ee97f5748840ae1a81f8f2dee75f'
|
||
},
|
||
omitBy : {
|
||
description: `### omitBy
|
||
|
||
Creates an object composed of the properties the given function returns falsey for. The function is invoked with two arguments: (value, key).
|
||
|
||
Use \`Object.keys(obj)\` and \`Array.filter()\`to remove the keys for which \`fn\` returns a truthy value.
|
||
Use \`Array.reduce()\` to convert the filtered keys back to an object with the corresponding key-value pairs.
|
||
|
||
`,
|
||
comments: [`// { b: '2' }`],
|
||
hash: '2f396b91794c853304732568dab330e91f9182553b452268cb19941042087b98'
|
||
},
|
||
on : {
|
||
description: `### on
|
||
|
||
Adds an event listener to an element with the ability to use event delegation.
|
||
|
||
Use \`EventTarget.addEventListener()\` to add an event listener to an element. If there is a \`target\` property supplied to the options object, ensure the event target matches the target specified and then invoke the callback by supplying the correct \`this\` context.
|
||
Returns a reference to the custom delegator function, in order to be possible to use with [\`off\`](#off).
|
||
Omit \`opts\` to default to non-delegation behavior and event bubbling.
|
||
|
||
`,
|
||
comments: [`// logs '!' upon clicking the body`,`// logs '!' upon clicking a \`p\` element child of the body`,`// use capturing instead of bubbling`],
|
||
hash: 'c5f26491c28670e971d9049b74ff79ed933a2d92ad29a117d324c131e8205be5'
|
||
},
|
||
once : {
|
||
description: `### once
|
||
|
||
Ensures a function is called only once.
|
||
|
||
Utilizing a closure, use a flag, \`called\`, and set it to \`true\` once the function is called for the first time, preventing it from being called again. In order to allow the function to have its \`this\` context changed (such as in an event listener), the \`function\` keyword must be used, and the supplied function must have the context applied.
|
||
Allow the function to be supplied with an arbitrary number of arguments using the rest/spread (\`...\`) operator.
|
||
|
||
`,
|
||
comments: [`// document.body, MouseEvent`,`// only runs \`startApp\` once upon click`],
|
||
hash: '60c1b3e83e55b2cef66ffc26f92f419998b1aff51c6194a176c35c20384930cb'
|
||
},
|
||
onUserInputChange : {
|
||
description: `### onUserInputChange
|
||
|
||
Run the callback whenever the user input type changes (\`mouse\` or \`touch\`). Useful for enabling/disabling code depending on the input device. This process is dynamic and works with hybrid devices (e.g. touchscreen laptops).
|
||
|
||
Use two event listeners. Assume \`mouse\` input initially and bind a \`touchstart\` event listener to the document.
|
||
On \`touchstart\`, add a \`mousemove\` event listener to listen for two consecutive \`mousemove\` events firing within 20ms, using \`performance.now()\`.
|
||
Run the callback with the input type as an argument in either of these situations.
|
||
|
||
`,
|
||
comments: [],
|
||
hash: '8b40bbf8048d58d7b1f709af838ac2d50b7f345a6c799ad95861963e05481dff'
|
||
},
|
||
orderBy : {
|
||
description: `### orderBy
|
||
|
||
Returns a sorted array of objects ordered by properties and orders.
|
||
|
||
Uses \`Array.sort()\`, \`Array.reduce()\` on the \`props\` array with a default value of \`0\`, use array destructuring to swap the properties position depending on the order passed.
|
||
If no \`orders\` array is passed it sort by \`'asc'\` by default.
|
||
|
||
`,
|
||
comments: [`// [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}]`,`// [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]`],
|
||
hash: '266a08f6be096e96c3a744709a2fd2e21827857eda5a6884155e04e49beb5e65'
|
||
},
|
||
over : {
|
||
description: `### over
|
||
|
||
Creates a function that invokes each provided function with the arguments it receives and returns the results.
|
||
|
||
Use \`Array.map()\` and \`Function.apply()\` to apply each function to the given arguments.
|
||
|
||
`,
|
||
comments: [`// [1,5]`],
|
||
hash: '9a8f4fea12aed02d983e980befbffefc23bdfc6c736e0a2647f88e4aa2700ed7'
|
||
},
|
||
overArgs : {
|
||
description: `### overArgs
|
||
|
||
Creates a function that invokes the provided function with its arguments transformed.
|
||
|
||
Use \`Array.map()\` to apply \`transforms\` to \`args\` in combination with the spread operator (\`...\`) to pass the transformed arguments to \`fn\`.
|
||
|
||
`,
|
||
comments: [`// [81, 6]`],
|
||
hash: '3264685ac827f036d70317c328dd87f21a3f73e9731da27e3bffcab4b421bd94'
|
||
},
|
||
palindrome : {
|
||
description: `### palindrome
|
||
|
||
Returns \`true\` if the given string is a palindrome, \`false\` otherwise.
|
||
|
||
Convert string \`String.toLowerCase()\` and use \`String.replace()\` to remove non-alphanumeric characters from it.
|
||
Then, \`String.split('')\` into individual characters, \`Array.reverse()\`, \`String.join('')\` and compare to the original, unreversed string, after converting it \`String.tolowerCase()\`.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: '4a84be9d1a9332a9c9d22006ff4ed45c94a13e31a71b873d37d68d69cf1abca2'
|
||
},
|
||
parseCookie : {
|
||
description: `### parseCookie
|
||
|
||
Parse an HTTP Cookie header string and return an object of all cookie name-value pairs.
|
||
|
||
Use \`String.split(';')\` to separate key-value pairs from each other.
|
||
Use \`Array.map()\` and \`String.split('=')\` to separate keys from values in each pair.
|
||
Use \`Array.reduce()\` and \`decodeURIComponent()\` to create an object with all key-value pairs.
|
||
|
||
`,
|
||
comments: [`// { foo: 'bar', equation: 'E=mc^2' }`],
|
||
hash: '6f22c6f53079b8a66725eabb27a7eabdc210fb6256d8bbae9cc6a0fbef96faac'
|
||
},
|
||
partial : {
|
||
description: `### partial
|
||
|
||
Creates a function that invokes \`fn\` with \`partials\` prepended to the arguments it receives.
|
||
|
||
Use the spread operator (\`...\`) to prepend \`partials\` to the list of arguments of \`fn\`.
|
||
|
||
`,
|
||
comments: [`// 'Hello John!'`],
|
||
hash: 'd3827db0162532e28149d341c08b1d2ae72f36b0b3b480407ef7dca211c9abb1'
|
||
},
|
||
partialRight : {
|
||
description: `### partialRight
|
||
|
||
Creates a function that invokes \`fn\` with \`partials\` appended to the arguments it receives.
|
||
|
||
Use the spread operator (\`...\`) to append \`partials\` to the list of arguments of \`fn\`.
|
||
|
||
`,
|
||
comments: [`// 'Hello John!'`],
|
||
hash: 'd7e22ab0e1ce71ae47687441dd234141f2a2f70fab5f3a6b59d7015e924e517a'
|
||
},
|
||
partition : {
|
||
description: `### partition
|
||
|
||
Groups the elements into two arrays, depending on the provided function's truthiness for each element.
|
||
|
||
Use \`Array.reduce()\` to create an array of two arrays.
|
||
Use \`Array.push()\` to add elements for which \`fn\` returns \`true\` to the first array and elements for which \`fn\` returns \`false\` to the second one.
|
||
|
||
`,
|
||
comments: [`// [[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]]`],
|
||
hash: 'e1a4fb7bf8b719a0e43b5c4b765c3989b5a856311602023e8750f1d0a018f911'
|
||
},
|
||
percentile : {
|
||
description: `### percentile
|
||
|
||
Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value.
|
||
|
||
Use \`Array.reduce()\` to calculate how many numbers are below the value and how many are the same value and apply the percentile formula.
|
||
|
||
`,
|
||
comments: [`// 55`],
|
||
hash: 'c7d7b7e8ba58d26a2a1f640c859ffc85ad128b0de5172a99e104e75be2999ebd'
|
||
},
|
||
pick : {
|
||
description: `### pick
|
||
|
||
Picks the key-value pairs corresponding to the given keys from an object.
|
||
|
||
Use \`Array.reduce()\` to convert the filtered/picked keys back to an object with the corresponding key-value pairs if the key exists in the object.
|
||
|
||
`,
|
||
comments: [`// { 'a': 1, 'c': 3 }`],
|
||
hash: 'd8287e0d701b51b904f5772908509223c30a47cf9d33dc5ae606001d98ddf73d'
|
||
},
|
||
pickBy : {
|
||
description: `### pickBy
|
||
|
||
Creates an object composed of the properties the given function returns truthy for. The function is invoked with two arguments: (value, key).
|
||
|
||
Use \`Object.keys(obj)\` and \`Array.filter()\`to remove the keys for which \`fn\` returns a falsey value.
|
||
Use \`Array.reduce()\` to convert the filtered keys back to an object with the corresponding key-value pairs.
|
||
|
||
`,
|
||
comments: [`// { 'a': 1, 'c': 3 }`],
|
||
hash: '6eb05d39c09752618bd51f4d98b90f4163d8a297f1e60e37aca10d7cd81099a7'
|
||
},
|
||
pipeAsyncFunctions : {
|
||
description: `### pipeAsyncFunctions
|
||
|
||
Performs left-to-right function composition for asynchronous functions.
|
||
|
||
Use \`Array.reduce()\` with the spread operator (\`...\`) to perform left-to-right function composition using \`Promise.then()\`.
|
||
The functions can return a combination of: simple values, \`Promise\`'s, or they can be defined as \`async\` ones returning through \`await\`.
|
||
All functions must be unary.
|
||
|
||
`,
|
||
comments: [`// 15 (after one second)`],
|
||
hash: '52363ec2842422126ca0544d9982603afd8ae4b8bf315d76c17690c91eb06e0f'
|
||
},
|
||
pipeFunctions : {
|
||
description: `### pipeFunctions
|
||
|
||
Performs left-to-right function composition.
|
||
|
||
Use \`Array.reduce()\` with the spread operator (\`...\`) to perform left-to-right function composition.
|
||
The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.
|
||
|
||
`,
|
||
comments: [`// 15`],
|
||
hash: '80753dd7af0282c9fdf0ceb615b8d7dbdcbcf41aa4c366db209672a79828c955'
|
||
},
|
||
pluralize : {
|
||
description: `### pluralize
|
||
|
||
Returns the singular or plural form of the word based on the input number. If the first argument is an \`object\`, it will use a closure by returning a function that can auto-pluralize words that don't simply end in \`s\` if the supplied dictionary contains the word.
|
||
|
||
If \`num\` is either \`-1\` or \`1\`, return the singular form of the word. If \`num\` is any other number, return the plural form. Omit the third argument to use the default of the singular word + \`s\`, or supply a custom pluralized word when necessary. If the first argument is an \`object\`, utilize a closure by returning a function which can use the supplied dictionary to resolve the correct plural form of the word.
|
||
|
||
`,
|
||
comments: [`// 'apples'`,`// 'apple'`,`// 'apples'`,`// 'people'`,`// 'people'`],
|
||
hash: '68a521d9ba019afbdd726791f0a2aaab948ad142f3b64b657e5a88239f9e6cb8'
|
||
},
|
||
powerset : {
|
||
description: `### powerset
|
||
|
||
Returns the powerset of a given array of numbers.
|
||
|
||
Use \`Array.reduce()\` combined with \`Array.map()\` to iterate over elements and combine into an array containing all combinations.
|
||
|
||
`,
|
||
comments: [`// [[], [1], [2], [2,1]]`],
|
||
hash: '3a6a31847448422578e579e973eaa09481e361b871f069d86a6656eb01bfe302'
|
||
},
|
||
prettyBytes : {
|
||
description: `### prettyBytes
|
||
|
||
Converts a number in bytes to a human-readable string.
|
||
|
||
Use an array dictionary of units to be accessed based on the exponent.
|
||
Use \`Number.toPrecision()\` to truncate the number to a certain number of digits.
|
||
Return the prettified string by building it up, taking into account the supplied options and whether it is negative or not.
|
||
Omit the second argument, \`precision\`, to use a default precision of \`3\` digits.
|
||
Omit the third argument, \`addSpace\`, to add space between the number and unit by default.
|
||
|
||
`,
|
||
comments: [`// "1 KB"`,`// "-27.145 GB"`,`// "123MB"`],
|
||
hash: '08cbd19f78bf3794926f6c3d138587567efcff45dd176d9d4f76466be174f99b'
|
||
},
|
||
primes : {
|
||
description: `### primes
|
||
|
||
Generates primes up to a given number, using the Sieve of Eratosthenes.
|
||
|
||
Generate an array from \`2\` to the given number. Use \`Array.filter()\` to filter out the values divisible by any number from \`2\` to the square root of the provided number.
|
||
|
||
`,
|
||
comments: [`// [2,3,5,7]`],
|
||
hash: '9c1be212a3c197ecfc3427fb7cf85724f85c77b1a82f785f492ac5b016e0b3de'
|
||
},
|
||
promisify : {
|
||
description: `### promisify
|
||
|
||
Converts an asynchronous function to return a promise.
|
||
|
||
Use currying to return a function returning a \`Promise\` that calls the original function.
|
||
Use the \`...rest\` operator to pass in all the parameters.
|
||
|
||
*In Node 8+, you can use [\`util.promisify\`](https://nodejs.org/api/util.html#util_util_promisify_original)*
|
||
|
||
`,
|
||
comments: [`//nodejs.org/api/util.html#util_util_promisify_original)*`,`// // Promise resolves after 2s`],
|
||
hash: 'ac038beb88d33e2605efddd8ff96031cd8108b4a3836614ebdd38e1f0865539e'
|
||
},
|
||
pull : {
|
||
description: `### pull
|
||
|
||
Mutates the original array to filter out the values specified.
|
||
|
||
Use \`Array.filter()\` and \`Array.includes()\` to pull out the values that are not needed.
|
||
Use \`Array.length = 0\` to mutate the passed in an array by resetting it's length to zero and \`Array.push()\` to re-populate it with only the pulled values.
|
||
|
||
_(For a snippet that does not mutate the original array see [\`without\`](#without))_
|
||
|
||
`,
|
||
comments: [`// myArray = [ 'b', 'b' ]`],
|
||
hash: 'd8b2ac76b7ea21aa33bdd47642b7eb55caa249ce81633bfff5ddf247aead45e8'
|
||
},
|
||
pullAtIndex : {
|
||
description: `### pullAtIndex
|
||
|
||
Mutates the original array to filter out the values at the specified indexes.
|
||
|
||
Use \`Array.filter()\` and \`Array.includes()\` to pull out the values that are not needed.
|
||
Use \`Array.length = 0\` to mutate the passed in an array by resetting it's length to zero and \`Array.push()\` to re-populate it with only the pulled values.
|
||
Use \`Array.push()\` to keep track of pulled values
|
||
|
||
`,
|
||
comments: [`// myArray = [ 'a', 'c' ] , pulled = [ 'b', 'd' ]`],
|
||
hash: '8962d4202f31d5bb26a63d1b8f0e50cbaf10c5c94d9a8ddc93a957ae5dd78fd1'
|
||
},
|
||
pullAtValue : {
|
||
description: `### pullAtValue
|
||
|
||
Mutates the original array to filter out the values specified. Returns the removed elements.
|
||
|
||
Use \`Array.filter()\` and \`Array.includes()\` to pull out the values that are not needed.
|
||
Use \`Array.length = 0\` to mutate the passed in an array by resetting it's length to zero and \`Array.push()\` to re-populate it with only the pulled values.
|
||
Use \`Array.push()\` to keep track of pulled values
|
||
|
||
`,
|
||
comments: [`// myArray = [ 'a', 'c' ] , pulled = [ 'b', 'd' ]`],
|
||
hash: '68b9e5821aeea26859007f3b1664c5a3da0d1ccec8ddee5864964bcc470afdd4'
|
||
},
|
||
pullBy : {
|
||
description: `### pullBy
|
||
|
||
Mutates the original array to filter out the values specified, based on a given iterator function.
|
||
|
||
Check if the last argument provided in a function.
|
||
Use \`Array.map()\` to apply the iterator function \`fn\` to all array elements.
|
||
Use \`Array.filter()\` and \`Array.includes()\` to pull out the values that are not needed.
|
||
Use \`Array.length = 0\` to mutate the passed in an array by resetting it's length to zero and \`Array.push()\` to re-populate it with only the pulled values.
|
||
|
||
`,
|
||
comments: [`// myArray = [{ x: 2 }]`],
|
||
hash: '71a41aef1aefdde0cc345d10347ef6c9a998868f219bed854218c5f3b47f573e'
|
||
},
|
||
randomHexColorCode : {
|
||
description: `### randomHexColorCode
|
||
|
||
Generates a random hexadecimal color code.
|
||
|
||
Use \`Math.random\` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using \`toString(16)\`.
|
||
|
||
`,
|
||
comments: [`// "#e34155"`],
|
||
hash: '6af176c0007886231038d513047c089a03200647c960ecb27b7b624e2629c913'
|
||
},
|
||
randomIntArrayInRange : {
|
||
description: `### randomIntArrayInRange
|
||
|
||
Returns an array of n random integers in the specified range.
|
||
|
||
Use \`Array.from()\` to create an empty array of the specific length, \`Math.random()\` to generate a random number and map it to the desired range, using \`Math.floor()\` to make it an integer.
|
||
|
||
`,
|
||
comments: [`// [ 34, 14, 27, 17, 30, 27, 20, 26, 21, 14 ]`],
|
||
hash: '0e2974d577b4265fee1d9996d563571c50baed64300e7e26a58e5afe2460d606'
|
||
},
|
||
randomIntegerInRange : {
|
||
description: `### randomIntegerInRange
|
||
|
||
Returns a random integer in the specified range.
|
||
|
||
Use \`Math.random()\` to generate a random number and map it to the desired range, using \`Math.floor()\` to make it an integer.
|
||
|
||
`,
|
||
comments: [`// 2`],
|
||
hash: '78b3f180ecba4d169a3c76ba2c9d76cde5646f429a66e13733dfdae1a0506007'
|
||
},
|
||
randomNumberInRange : {
|
||
description: `### randomNumberInRange
|
||
|
||
Returns a random number in the specified range.
|
||
|
||
Use \`Math.random()\` to generate a random value, map it to the desired range using multiplication.
|
||
|
||
`,
|
||
comments: [`// 6.0211363285087005`],
|
||
hash: '6878158127b623c4ab840fe1b40214a580f9f747ce38530fd3dfc3af38af6c8f'
|
||
},
|
||
readFileLines : {
|
||
description: `### readFileLines
|
||
|
||
Returns an array of lines from the specified file.
|
||
|
||
Use \`readFileSync\` function in \`fs\` node package to create a \`Buffer\` from a file.
|
||
convert buffer to string using \`toString(encoding)\` function.
|
||
creating an array from contents of file by \`split\`ing file content line by line (each \`\n\`).
|
||
|
||
`,
|
||
comments: [`// ['line1', 'line2', 'line3']`],
|
||
hash: 'a9f5f5500cf6380c2bb653744df639951a76c206d6228de6c178a686ffff2de5'
|
||
},
|
||
rearg : {
|
||
description: `### rearg
|
||
|
||
Creates a function that invokes the provided function with its arguments arranged according to the specified indexes.
|
||
|
||
Use \`Array.reduce()\` and \`Array.indexOf()\` to reorder arguments based on \`indexes\` in combination with the spread operator (\`...\`) to pass the transformed arguments to \`fn\`.
|
||
|
||
`,
|
||
comments: [`// ['a', 'b', 'c']`],
|
||
hash: '5b85a99357428eee2d57fb2876db6e9d78efb19e8c16670790fcc821a910984b'
|
||
},
|
||
redirect : {
|
||
description: `### redirect
|
||
|
||
Redirects to a specified URL.
|
||
|
||
Use \`window.location.href\` or \`window.location.replace()\` to redirect to \`url\`.
|
||
Pass a second argument to simulate a link click (\`true\` - default) or an HTTP redirect (\`false\`).
|
||
|
||
`,
|
||
comments: [`//google.com');`],
|
||
hash: '1d4c683ca10407fbfa443edadfd4e0841899b0ba492f50535e8cd3bc4ee77e19'
|
||
},
|
||
reducedFilter : {
|
||
description: `### reducedFilter
|
||
|
||
Filter an array of objects based on a condition while also filtering out unspecified keys.
|
||
|
||
Use \`Array.filter()\` to filter the array based on the predicate \`fn\` so that it returns the objects for which the condition returned a truthy value.
|
||
On the filtered array, use \`Array.map()\` to return the new object using \`Array.reduce()\` to filter out the keys which were not supplied as the \`keys\` argument.
|
||
|
||
`,
|
||
comments: [`// [{ id: 2, name: 'mike'}]`],
|
||
hash: 'fe7eaeaa58db860461ce1c2cb8a98fb59ef1ea90084e7775ef544cbbdb9707f2'
|
||
},
|
||
reduceSuccessive : {
|
||
description: `### reduceSuccessive
|
||
|
||
Applies a function against an accumulator and each element in the array (from left to right), returning an array of successively reduced values.
|
||
|
||
Use \`Array.reduce()\` to apply the given function to the given array, storing each new result.
|
||
|
||
`,
|
||
comments: [`// [0, 1, 3, 6, 10, 15, 21]`],
|
||
hash: '5866ff21a2aa6f7cf2980a3da4b1bddb9e4d6316e9f36efe108cc298af1e8d42'
|
||
},
|
||
reduceWhich : {
|
||
description: `### reduceWhich
|
||
|
||
Returns the minimum/maximum value of an array, after applying the provided function to set comparing rule.
|
||
|
||
Use \`Array.reduce()\` in combination with the \`comparator\` function to get the appropriate element in the array.
|
||
You can omit the second parameter, \`comparator\`, to use the default one that returns the minimum element in the array.
|
||
|
||
`,
|
||
comments: [`// 1`,`// 3`,`// {name: "Lucy", age: 9}`],
|
||
hash: 'ca952b8690c74fe12ce0baa6c61279f267b68794e59380a7c6b586207d4e3d30'
|
||
},
|
||
remove : {
|
||
description: `### remove
|
||
|
||
Removes elements from an array for which the given function returns \`false\`.
|
||
|
||
Use \`Array.filter()\` to find array elements that return truthy values and \`Array.reduce()\` to remove elements using \`Array.splice()\`.
|
||
The \`func\` is invoked with three arguments (\`value, index, array\`).
|
||
|
||
`,
|
||
comments: [`// [2, 4]`],
|
||
hash: '60d3d3a8dc9249f1a98a0aea91e199c089825afa9c51d2a43fd79794f0f070dc'
|
||
},
|
||
removeNonASCII : {
|
||
description: `### removeNonASCII
|
||
|
||
Removes non-printable ASCII characters.
|
||
|
||
Use a regular expression to remove non-printable ASCII characters.
|
||
|
||
`,
|
||
comments: [`// 'lorem-ipsum'`],
|
||
hash: 'e16f5691d22aa4cd48e1b64f33ae50f973fffa168264c15c4602c595b9fdfec7'
|
||
},
|
||
reverseString : {
|
||
description: `### reverseString
|
||
|
||
Reverses a string.
|
||
|
||
Use the spread operator (\`...\`) and \`Array.reverse()\` to reverse the order of the characters in the string.
|
||
Combine characters to get a string using \`String.join('')\`.
|
||
|
||
`,
|
||
comments: [`// 'raboof'`],
|
||
hash: '100fbfed8e5598b00cd6d324c8b17ed4b5ee80469e49d9e27b7e9290d893ecb9'
|
||
},
|
||
RGBToHex : {
|
||
description: `### RGBToHex
|
||
|
||
Converts the values of RGB components to a color code.
|
||
|
||
Convert given RGB parameters to hexadecimal string using bitwise left-shift operator (\`<<\`) and \`toString(16)\`, then \`String.padStart(6,'0')\` to get a 6-digit hexadecimal value.
|
||
|
||
`,
|
||
comments: [`// 'ffa501'`],
|
||
hash: '0b3bc3119ca3ec80882c1413a5f5e47612233e075af6e0e5939f27da28e34f96'
|
||
},
|
||
round : {
|
||
description: `### round
|
||
|
||
Rounds a number to a specified amount of digits.
|
||
|
||
Use \`Math.round()\` and template literals to round the number to the specified number of digits.
|
||
Omit the second argument, \`decimals\` to round to an integer.
|
||
|
||
`,
|
||
comments: [`// 1.01`],
|
||
hash: 'd4f32a82cd93e9abc5d7222610eed8f6a46a7ebbf4eed4f57035625947890a4a'
|
||
},
|
||
runAsync : {
|
||
description: `### runAsync
|
||
|
||
Runs a function in a separate thread by using a [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), allowing long running functions to not block the UI.
|
||
|
||
Create a new \`Worker\` using a \`Blob\` object URL, the contents of which should be the stringified version of the supplied function.
|
||
Immediately post the return value of calling the function back.
|
||
Return a promise, listening for \`onmessage\` and \`onerror\` events and resolving the data posted back from the worker, or throwing an error.
|
||
|
||
`,
|
||
comments: [`//developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), allowing long running functions to not block the UI.`,`// 209685000000`,`// 1000`,`// 'undefined'`],
|
||
hash: '8342955273acd8a377c9786fd6a504da3d6d4482d5f5a4222451a3520ce5fd6a'
|
||
},
|
||
runPromisesInSeries : {
|
||
description: `### runPromisesInSeries
|
||
|
||
Runs an array of promises in series.
|
||
|
||
Use \`Array.reduce()\` to create a promise chain, where each promise returns the next promise when resolved.
|
||
|
||
`,
|
||
comments: [`// Executes each promise sequentially, taking a total of 3 seconds to complete`],
|
||
hash: '774992e29bd2e84cb77cf84625cb49427b396265f929f222ee5be917eb3feb51'
|
||
},
|
||
sample : {
|
||
description: `### sample
|
||
|
||
Returns a random element from an array.
|
||
|
||
Use \`Math.random()\` to generate a random number, multiply it by \`length\` and round it of to the nearest whole number using \`Math.floor()\`.
|
||
This method also works with strings.
|
||
|
||
`,
|
||
comments: [`// 9`],
|
||
hash: 'b05e5107fb5291fdc235d60e9e5f956858aa89bdf4a31b14d7af00f107c83f0c'
|
||
},
|
||
sampleSize : {
|
||
description: `### sampleSize
|
||
|
||
Gets \`n\` random elements at unique keys from \`array\` up to the size of \`array\`.
|
||
|
||
Shuffle the array using the [Fisher-Yates algorithm](https://github.com/chalarangelo/30-seconds-of-code#shuffle).
|
||
Use \`Array.slice()\` to get the first \`n\` elements.
|
||
Omit the second argument, \`n\` to get only one element at random from the array.
|
||
|
||
`,
|
||
comments: [`//github.com/chalarangelo/30-seconds-of-code#shuffle).`,`// [3,1]`,`// [2,3,1]`],
|
||
hash: '5cc2e02485d627d9dd4c254292aae0277265126f92974719954f30a5f406ef17'
|
||
},
|
||
scrollToTop : {
|
||
description: `### scrollToTop
|
||
|
||
Smooth-scrolls to the top of the page.
|
||
|
||
Get distance from top using \`document.documentElement.scrollTop\` or \`document.body.scrollTop\`.
|
||
Scroll by a fraction of the distance from the top. Use \`window.requestAnimationFrame()\` to animate the scrolling.
|
||
|
||
`,
|
||
comments: [],
|
||
hash: 'cc386ab65d09fc0e3d56ae9d64eacfd1815cbd862b376b67857d26735a0c4f4a'
|
||
},
|
||
sdbm : {
|
||
description: `### sdbm
|
||
|
||
Hashes the input string into a whole number.
|
||
|
||
Use \`String.split('')\` and \`Array.reduce()\` to create a hash of the input string, utilizing bit shifting.
|
||
|
||
`,
|
||
comments: [`// -3521204949`],
|
||
hash: '24ef18cf8da4d2129dac1be013bd68c058333cb527938571c594ff400639cc89'
|
||
},
|
||
serializeCookie : {
|
||
description: `### serializeCookie
|
||
|
||
Serialize a cookie name-value pair into a Set-Cookie header string.
|
||
|
||
Use template literals and \`encodeURIComponent()\` to create the appropriate string.
|
||
|
||
`,
|
||
comments: [`// 'foo=bar'`],
|
||
hash: 'd00538ab5aba3ac223daa0e5301037622296acab3127eaca3066870570709f1a'
|
||
},
|
||
setStyle : {
|
||
description: `### setStyle
|
||
|
||
Sets the value of a CSS rule for the specified element.
|
||
|
||
Use \`element.style\` to set the value of the CSS rule for the specified element to \`val\`.
|
||
|
||
`,
|
||
comments: [`// The first <p> element on the page will have a font-size of 20px`],
|
||
hash: '8c69204b5c26d9e05eeba2b4f3f0b8252d6a98161da34c71b19eeb387e5443a2'
|
||
},
|
||
shallowClone : {
|
||
description: `### shallowClone
|
||
|
||
Creates a shallow clone of an object.
|
||
|
||
Use \`Object.assign()\` and an empty object (\`{}\`) to create a shallow clone of the original.
|
||
|
||
`,
|
||
comments: [`// a !== b`],
|
||
hash: '54d410e1b4dfabeed00abfa49d2f0f2765c190e18d08438f5f70e0ff48c6833e'
|
||
},
|
||
show : {
|
||
description: `### show
|
||
|
||
Shows all the elements specified.
|
||
|
||
Use the spread operator (\`...\`) and \`Array.forEach()\` to clear the \`display\` property for each element specified.
|
||
|
||
`,
|
||
comments: [`// Shows all <img> elements on the page`],
|
||
hash: 'fdead8b9b296bd35fa989791cfc576da2cdfd01121d3d00e0a96ed09557e1a91'
|
||
},
|
||
shuffle : {
|
||
description: `### shuffle
|
||
|
||
Randomizes the order of the values of an array, returning a new array.
|
||
|
||
Uses the [Fisher-Yates algorithm](https://github.com/chalarangelo/30-seconds-of-code#shuffle) to reorder the elements of the array.
|
||
|
||
`,
|
||
comments: [`//github.com/chalarangelo/30-seconds-of-code#shuffle) to reorder the elements of the array.`,`// [2,3,1], foo = [1,2,3]`],
|
||
hash: '65c945a0bfa2f4ab4d882055cf8ba33d27b32a3a9431dadefe9abf784d080fd5'
|
||
},
|
||
similarity : {
|
||
description: `### similarity
|
||
|
||
Returns an array of elements that appear in both arrays.
|
||
|
||
Use \`Array.filter()\` to remove values that are not part of \`values\`, determined using \`Array.includes()\`.
|
||
|
||
`,
|
||
comments: [`// [1,2]`],
|
||
hash: 'bb974be5244001acd3b49984f5362a12c4358a74974a8f0fa3e5a3fa6e06d17b'
|
||
},
|
||
size : {
|
||
description: `### size
|
||
|
||
Get size of arrays, objects or strings.
|
||
|
||
Get type of \`val\` (\`array\`, \`object\` or \`string\`).
|
||
Use \`length\` property for arrays.
|
||
Use \`length\` or \`size\` value if available or number of keys for objects.
|
||
Use \`size\` of a [\`Blob\` object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) created from \`val\` for strings.
|
||
|
||
Split strings into array of characters with \`split('')\` and return its length.
|
||
|
||
`,
|
||
comments: [`//developer.mozilla.org/en-US/docs/Web/API/Blob) created from \`val\` for strings.`,`// 5`,`// 4`,`// 3`],
|
||
hash: '3e220ee4374848c9d59477b7bd113b35a21064aaec40cfb5fcf6a8ee720f14f0'
|
||
},
|
||
sleep : {
|
||
description: `### sleep
|
||
|
||
Delays the execution of an asynchronous function.
|
||
|
||
Delay executing part of an \`async\` function, by putting it to sleep, returning a \`Promise\`.
|
||
|
||
`,
|
||
comments: [],
|
||
hash: '3c3bcba169002b447bfd34cff40ca430c8eb470a09d8dbddbb939c9ef8515921'
|
||
},
|
||
sortCharactersInString : {
|
||
description: `### sortCharactersInString
|
||
|
||
Alphabetically sorts the characters in a string.
|
||
|
||
Use the spread operator (\`...\`), \`Array.sort()\` and \`String.localeCompare()\` to sort the characters in \`str\`, recombine using \`String.join('')\`.
|
||
|
||
`,
|
||
comments: [`// 'aabbceg'`],
|
||
hash: '79d6f6019e15d5bce0ad50eb3790db8a321271f5e37117cd57c8a9ef0637cbc3'
|
||
},
|
||
sortedIndex : {
|
||
description: `### sortedIndex
|
||
|
||
Returns the lowest index at which value should be inserted into array in order to maintain its sort order.
|
||
|
||
Check if the array is sorted in descending order (loosely).
|
||
Use \`Array.findIndex()\` to find the appropriate index where the element should be inserted.
|
||
|
||
`,
|
||
comments: [`// 1`,`// 1`],
|
||
hash: 'f71ff3e3dd1af415d232b7fc77f380495286673603ea267ccd815c9cef81af8e'
|
||
},
|
||
sortedIndexBy : {
|
||
description: `### sortedIndexBy
|
||
|
||
Returns the lowest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.
|
||
|
||
Check if the array is sorted in descending order (loosely).
|
||
Use \`Array.findIndex()\` to find the appropriate index where the element should be inserted, based on the iterator function \`fn\`.
|
||
|
||
`,
|
||
comments: [`// 0`],
|
||
hash: '143b847ad0bc2897c2099653a7f43ca95d52306c5a7d073e91578170a73e0498'
|
||
},
|
||
sortedLastIndex : {
|
||
description: `### sortedLastIndex
|
||
|
||
Returns the highest index at which value should be inserted into array in order to maintain its sort order.
|
||
|
||
Check if the array is sorted in descending order (loosely).
|
||
Use \`Array.map()\` to map each element to an array with its index and value.
|
||
Use \`Array.reverse()\` and \`Array.findIndex()\` to find the appropriate last index where the element should be inserted.
|
||
|
||
`,
|
||
comments: [`// 3`],
|
||
hash: 'a3d6e006f72169254081eb3ffe14d7e17208f6b809cb18ebffff059fe94b1a73'
|
||
},
|
||
sortedLastIndexBy : {
|
||
description: `### sortedLastIndexBy
|
||
|
||
Returns the highest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.
|
||
|
||
Check if the array is sorted in descending order (loosely).
|
||
Use \`Array.reverse()\` and \`Array.findIndex()\` to find the appropriate last index where the element should be inserted, based on the iterator function \`fn\`..
|
||
|
||
`,
|
||
comments: [`// 1`],
|
||
hash: '956e42540442c922f21383528cac62b34711ab910416eb18f0b5beacc39662f0'
|
||
},
|
||
splitLines : {
|
||
description: `### splitLines
|
||
|
||
Splits a multiline string into an array of lines.
|
||
|
||
Use \`String.split()\` and a regular expression to match line breaks and create an array.
|
||
|
||
`,
|
||
comments: [`// ['This', 'is a', 'multiline', 'string.' , '']`],
|
||
hash: '50c743b336e91f39d93d065b36d86e7d25df053fa2a87b0ee0cbdf5b71aa77df'
|
||
},
|
||
spreadOver : {
|
||
description: `### spreadOver
|
||
|
||
Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.
|
||
|
||
Use closures and the spread operator (\`...\`) to map the array of arguments to the inputs of the function.
|
||
|
||
`,
|
||
comments: [`// 3`],
|
||
hash: '9a79940f01badd37efb5156b8e3d220c85601c99a6908b79fe9508d0cd4d8ff5'
|
||
},
|
||
standardDeviation : {
|
||
description: `### standardDeviation
|
||
|
||
Returns the standard deviation of an array of numbers.
|
||
|
||
Use \`Array.reduce()\` to calculate the mean, variance and the sum of the variance of the values, the variance of the values, then
|
||
determine the standard deviation.
|
||
You can omit the second argument to get the sample standard deviation or set it to \`true\` to get the population standard deviation.
|
||
|
||
`,
|
||
comments: [`// 13.284434142114991 (sample)`,`// 12.29899614287479 (population)`],
|
||
hash: '4b7af7c22167951b8d08b5299d77da7878c29ef2814f6861eb105b8a8b575205'
|
||
},
|
||
stripHTMLTags : {
|
||
description: `### stripHTMLTags
|
||
|
||
Removes HTML/XML tags from string.
|
||
|
||
Use a regular expression to remove HTML/XML tags from a string.
|
||
|
||
`,
|
||
comments: [`// 'lorem ipsum'`],
|
||
hash: 'ee2f284cf513dc1d61b4d366698555c240131d5fe8fc17bd19a4cf055091ce58'
|
||
},
|
||
sum : {
|
||
description: `### sum
|
||
|
||
Returns the sum of two or more numbers/arrays.
|
||
|
||
Use \`Array.reduce()\` to add each value to an accumulator, initialized with a value of \`0\`.
|
||
|
||
`,
|
||
comments: [`// 10`],
|
||
hash: '2cf7eb027c7f65533d9b4047c5ad69d0143327a3aa1b2d6b0691edce12f6e08e'
|
||
},
|
||
sumBy : {
|
||
description: `### sumBy
|
||
|
||
Returns the sum of an array, after mapping each element to a value using the provided function.
|
||
|
||
Use \`Array.map()\` to map each element to the value returned by \`fn\`, \`Array.reduce()\` to add each value to an accumulator, initialized with a value of \`0\`.
|
||
|
||
`,
|
||
comments: [`// 20`,`// 20`],
|
||
hash: 'f3bcd41f95581cc20202793baa5b3d63ff269848465bb42213fb3d9c80f4cf94'
|
||
},
|
||
sumPower : {
|
||
description: `### sumPower
|
||
|
||
Returns the sum of the powers of all the numbers from \`start\` to \`end\` (both inclusive).
|
||
|
||
Use \`Array.fill()\` to create an array of all the numbers in the target range, \`Array.map()\` and the exponent operator (\`**\`) to raise them to \`power\` and \`Array.reduce()\` to add them together.
|
||
Omit the second argument, \`power\`, to use a default power of \`2\`.
|
||
Omit the third argument, \`start\`, to use a default starting value of \`1\`.
|
||
|
||
`,
|
||
comments: [`// 385`,`//3025`,`//2925`],
|
||
hash: '8ea7437f0b31fb6be6445e80cc33d0362cb7b34a2cf3c4ef6fad57836e1164ee'
|
||
},
|
||
symmetricDifference : {
|
||
description: `### symmetricDifference
|
||
|
||
Returns the symmetric difference between two arrays.
|
||
|
||
Create a \`Set\` from each array, then use \`Array.filter()\` on each of them to only keep values not contained in the other.
|
||
|
||
`,
|
||
comments: [`// [3,4]`],
|
||
hash: 'fe09ab114e8ef0b7efcd9a00c911c66e1421b664a424fff51dd2bef6d1b967c5'
|
||
},
|
||
symmetricDifferenceBy : {
|
||
description: `### symmetricDifferenceBy
|
||
|
||
Returns the symmetric difference between two arrays, after applying the provided function to each array element of both.
|
||
|
||
Create a \`Set\` by applying \`fn\` to each array's elements, then use \`Array.filter()\` on each of them to only keep values not contained in the other.
|
||
|
||
`,
|
||
comments: [`// [ 1.2, 3.4 ]`],
|
||
hash: '1ab75f53cae9b9de08aaca4a9e0d2a2392ff67b1ac530277bb07c9824f452be4'
|
||
},
|
||
symmetricDifferenceWith : {
|
||
description: `### symmetricDifferenceWith
|
||
|
||
Returns the symmetric difference between two arrays, using a provided function as a comparator.
|
||
|
||
Use \`Array.filter()\` and \`Array.findIndex()\` to find the appropriate values.
|
||
|
||
`,
|
||
comments: [`// [1, 1.2, 3.9]`],
|
||
hash: '2025e03028071fc9ef7d47e86b9f4621723e365c3691e3e8d1acc28edf68eec0'
|
||
},
|
||
tail : {
|
||
description: `### tail
|
||
|
||
Returns all elements in an array except for the first one.
|
||
|
||
Return \`Array.slice(1)\` if the array's \`length\` is more than \`1\`, otherwise, return the whole array.
|
||
|
||
`,
|
||
comments: [`// [2,3]`,`// [1]`],
|
||
hash: '91f77b9037f3a2dc716f9e97982fd5895d5484e7f83f39bb68b2ffca6294a5f5'
|
||
},
|
||
take : {
|
||
description: `### take
|
||
|
||
Returns an array with n elements removed from the beginning.
|
||
|
||
Use \`Array.slice()\` to create a slice of the array with \`n\` elements taken from the beginning.
|
||
|
||
`,
|
||
comments: [`// [1, 2, 3]`,`// []`],
|
||
hash: 'fc2551cb197500c6e9cc6ed120b58994458a2c99b82cddc649ad70baf652a1af'
|
||
},
|
||
takeRight : {
|
||
description: `### takeRight
|
||
|
||
Returns an array with n elements removed from the end.
|
||
|
||
Use \`Array.slice()\` to create a slice of the array with \`n\` elements taken from the end.
|
||
|
||
`,
|
||
comments: [`// [ 2, 3 ]`,`// [3]`],
|
||
hash: 'c9f51be7e5753798e299dd472c35cfe022a6e324519ed1aaac2222c810d47074'
|
||
},
|
||
takeRightWhile : {
|
||
description: `### takeRightWhile
|
||
|
||
Removes elements from the end of an array until the passed function returns \`true\`. Returns the removed elements.
|
||
|
||
Loop through the array, using a \`for...of\` loop over \`Array.keys()\` until the returned value from the function is \`true\`.
|
||
Return the removed elements, using \`Array.reverse()\` and \`Array.slice()\`.
|
||
|
||
`,
|
||
comments: [`// [3, 4]`],
|
||
hash: 'ff08e161774aa0ee0cc9e1792ba8d60c3268cdb7042df3cf815a2fbcb54a911a'
|
||
},
|
||
takeWhile : {
|
||
description: `### takeWhile
|
||
|
||
Removes elements in an array until the passed function returns \`true\`. Returns the removed elements.
|
||
|
||
Loop through the array, using a \`for...of\` loop over \`Array.keys()\` until the returned value from the function is \`true\`.
|
||
Return the removed elements, using \`Array.slice()\`.
|
||
|
||
`,
|
||
comments: [`// [1, 2]`],
|
||
hash: '06d1ac21a754e223cabe85a88b7c3dcc80848e6f06008728855ae62137bf556c'
|
||
},
|
||
throttle : {
|
||
description: `### throttle
|
||
|
||
Creates a throttled function that only invokes the provided function at most once per every \`wait\` milliseconds
|
||
|
||
Use \`setTimeout()\` and \`clearTimeout()\` to throttle the given method, \`fn\`.
|
||
Use \`Function.apply()\` to apply the \`this\` context to the function and provide the necessary \`arguments\`.
|
||
Use \`Date.now()\` to keep track of the last time the throttled function was invoked.
|
||
Omit the second argument, \`wait\`, to set the timeout at a default of 0 ms.
|
||
|
||
`,
|
||
comments: [`// Will log the window dimensions at most every 250ms`],
|
||
hash: '7c436640f98253f3e8703882afff7c97414f3587dfe653003d41c68507b9ab5a'
|
||
},
|
||
times : {
|
||
description: `### times
|
||
|
||
Iterates over a callback \`n\` times
|
||
|
||
Use \`Function.call()\` to call \`fn\` \`n\` times or until it returns \`false\`.
|
||
Omit the last argument, \`context\`, to use an \`undefined\` object (or the global object in non-strict mode).
|
||
|
||
`,
|
||
comments: [`// 01234`],
|
||
hash: '81177986848b8ea067f9019c43923709a9798d1e599fb9ddbb6005096600db37'
|
||
},
|
||
timeTaken : {
|
||
description: `### timeTaken
|
||
|
||
Measures the time taken by a function to execute.
|
||
|
||
Use \`console.time()\` and \`console.timeEnd()\` to measure the difference between the start and end times to determine how long the callback took to execute.
|
||
|
||
`,
|
||
comments: [`// 1024, (logged): timeTaken: 0.02099609375ms`],
|
||
hash: '5c109f0acaf569c0878370b18b7526a1f5f075c482b8d0eca6de2528e258bee5'
|
||
},
|
||
toCamelCase : {
|
||
description: `### toCamelCase
|
||
|
||
Converts a string to camelcase.
|
||
|
||
Break the string into words and combine them capitalizing the first letter of each word, using a regexp.
|
||
|
||
`,
|
||
comments: [`// 'someDatabaseFieldName'`,`// 'someLabelThatNeedsToBeCamelized'`,`// 'someJavascriptProperty'`,`// 'someMixedStringWithSpacesUnderscoresAndHyphens'`],
|
||
hash: '0fc71e3c8dc9306e00ec868a340283f9a90d14bfc620e9105fa34aff95849e05'
|
||
},
|
||
toCurrency : {
|
||
description: `### toCurrency
|
||
|
||
Take a number and return specified currency formatting.
|
||
|
||
Use \`Intl.NumberFormat\` to enable country / currency sensitive formatting.
|
||
|
||
`,
|
||
comments: [`// €123,456.79 | currency: Euro | currencyLangFormat: Local`,`// €123,456.79 | currency: US Dollar | currencyLangFormat: English (United States)`,`// ۱۲۳٬۴۵۶٫۷۹ $ | currency: US Dollar | currencyLangFormat: Farsi`,`// ¥322,342,436,423 | currency: Japanese Yen | currencyLangFormat: Local`,`// 322 342 436 423 ¥ | currency: Japanese Yen | currencyLangFormat: Finnish`],
|
||
hash: 'd1c86c6f075b79b53b74aede9669101f1a07e89cc73ccabf347ad42674b1a33c'
|
||
},
|
||
toDecimalMark : {
|
||
description: `### toDecimalMark
|
||
|
||
Use \`toLocaleString()\` to convert a float-point arithmetic to the [Decimal mark](https://en.wikipedia.org/wiki/Decimal_mark) form. It makes a comma separated string from a number.
|
||
|
||
`,
|
||
comments: [`//en.wikipedia.org/wiki/Decimal_mark) form. It makes a comma separated string from a number.`,`// "12,305,030,388.909"`],
|
||
hash: '60a6869c136463b7cd17169c91a3df8baba1c4d5482918b6f93b7d898f1ed725'
|
||
},
|
||
toggleClass : {
|
||
description: `### toggleClass
|
||
|
||
Toggle a class for an element.
|
||
|
||
Use \`element.classList.toggle()\` to toggle the specified class for the element.
|
||
|
||
`,
|
||
comments: [`// The paragraph will not have the 'special' class anymore`],
|
||
hash: '8e84c13bd40d483eea6a3d26518d118e2ba4eb1cf32381345521925b5ca2c481'
|
||
},
|
||
toKebabCase : {
|
||
description: `### toKebabCase
|
||
|
||
Converts a string to kebab case.
|
||
|
||
Break the string into words and combine them adding \`-\` as a separator, using a regexp.
|
||
|
||
`,
|
||
comments: [`// 'camel-case'`,`// 'some-text'`,`// 'some-mixed-string-with-spaces-underscores-and-hyphens'`,`// "all-the-small-things"`,`// "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html"`],
|
||
hash: '661b36855eeb91fcb1bf514bcec9ac3474e30e9e54d111d29e4916528cab6640'
|
||
},
|
||
tomorrow : {
|
||
description: `### tomorrow
|
||
|
||
Results in a string representation of tomorrow's date.
|
||
Use \`new Date()\` to get today's date, adding one day using \`Date.getDate()\` and \`Date.setDate()\`, and converting the Date object to a string.
|
||
|
||
`,
|
||
comments: [`// 2017-12-27 (if current date is 2017-12-26)`],
|
||
hash: 'd6c258e73365607337f947d09aa229e45966e2a9585a7d39f81667ab88684f2d'
|
||
},
|
||
toOrdinalSuffix : {
|
||
description: `### toOrdinalSuffix
|
||
|
||
Adds an ordinal suffix to a number.
|
||
|
||
Use the modulo operator (\`%\`) to find values of single and tens digits.
|
||
Find which ordinal pattern digits match.
|
||
If digit is found in teens pattern, use teens ordinal.
|
||
|
||
`,
|
||
comments: [`// "123rd"`],
|
||
hash: '1325cac1de2f1437b19b9d23a72a4a88e7218ed20f7787ae15c7fc0953786c47'
|
||
},
|
||
toSafeInteger : {
|
||
description: `### toSafeInteger
|
||
|
||
Converts a value to a safe integer.
|
||
|
||
Use \`Math.max()\` and \`Math.min()\` to find the closest safe value.
|
||
Use \`Math.round()\` to convert to an integer.
|
||
|
||
`,
|
||
comments: [`// 3`,`// 9007199254740991`],
|
||
hash: '8416d92bd5d190468f9c9c73318228aa5898191983d1d941d6e43115d7ce63ba'
|
||
},
|
||
toSnakeCase : {
|
||
description: `### toSnakeCase
|
||
|
||
Converts a string to snake case.
|
||
|
||
Break the string into words and combine them adding \`_\` as a separator, using a regexp.
|
||
|
||
`,
|
||
comments: [`// 'camel_case'`,`// 'some_text'`,`// 'some_mixed_string_with_spaces_underscores_and_hyphens'`,`// "all_the_smal_things"`,`// "i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html"`],
|
||
hash: '6e6eab17f7ffa0d8330c38e6f250d07c149d1c382c7e30c983b20c100867a091'
|
||
},
|
||
transform : {
|
||
description: `### transform
|
||
|
||
Applies a function against an accumulator and each key in the object (from left to right).
|
||
|
||
Use \`Object.keys(obj)\` to iterate over each key in the object, \`Array.reduce()\` to call the apply the specified function against the given accumulator.
|
||
|
||
`,
|
||
comments: [`// { '1': ['a', 'c'], '2': ['b'] }`],
|
||
hash: '8edb3efaf27dc3bfdaceb112ffae32165eb9e9d3101fad1d77531538d3813273'
|
||
},
|
||
truncateString : {
|
||
description: `### truncateString
|
||
|
||
Truncates a string up to a specified length.
|
||
|
||
Determine if the string's \`length\` is greater than \`num\`.
|
||
Return the string truncated to the desired length, with \`'...'\` appended to the end or the original string.
|
||
|
||
`,
|
||
comments: [`// 'boom...'`],
|
||
hash: 'd108f89840fbd3b80322bb33fe5db0126cb27f87250b1ea5658311fead9abc99'
|
||
},
|
||
truthCheckCollection : {
|
||
description: `### truthCheckCollection
|
||
|
||
Checks if the predicate (second argument) is truthy on all elements of a collection (first argument).
|
||
|
||
Use \`Array.every()\` to check if each passed object has the specified property and if it returns a truthy value.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: 'ad9e91b1da020f616c65a49301df9fe45e1564515707741015f3e6f99829418e'
|
||
},
|
||
unary : {
|
||
description: `### unary
|
||
|
||
Creates a function that accepts up to one argument, ignoring any additional arguments.
|
||
|
||
Call the provided function, \`fn\`, with just the first argument given.
|
||
|
||
`,
|
||
comments: [`// [6, 8, 10]`],
|
||
hash: '80672a8ef916cbfd3c144c24d9a2ba8f61aae96d83fb6c65b788598f39b61086'
|
||
},
|
||
unescapeHTML : {
|
||
description: `### unescapeHTML
|
||
|
||
Unescapes escaped HTML characters.
|
||
|
||
Use \`String.replace()\` with a regex that matches the characters that need to be unescaped, using a callback function to replace each escaped character instance with its associated unescaped character using a dictionary (object).
|
||
|
||
`,
|
||
comments: [`// '<a href="#">Me & you</a>'`],
|
||
hash: '54547386a17cc030f6e53d3f9d7290b2ede349b7ebe223639e5fddb32c3ad941'
|
||
},
|
||
unflattenObject : {
|
||
description: `### unflattenObject
|
||
|
||
Unlatten an object with the paths for keys.
|
||
|
||
Use \`Object.keys(obj)\` combined with \`Array.reduce()\` to convert flattened path node to a leaf node.
|
||
If the value of a key contains a dot delimiter (\`.\`), use \`Array.split('.')\`, string transformations and \`JSON.parse()\` to create an object, then \`Object.assign()\` to create the leaf node.
|
||
Otherwise, add the appropriate key-value pair to the accumulator object.
|
||
|
||
`,
|
||
comments: [`// { a: { b: { c: 1 } }, d: 1 }`],
|
||
hash: '2b64c31a3c3a18db0b2e74699cd9a7f582a536143cdf8761a7d775c8baabc5f2'
|
||
},
|
||
unfold : {
|
||
description: `### unfold
|
||
|
||
Builds an array, using an iterator function and an initial seed value.
|
||
|
||
Use a \`while\` loop and \`Array.push()\` to call the function repeatedly until it returns \`false\`.
|
||
The iterator function accepts one argument (\`seed\`) and must always return an array with two elements ([\`value\`, \`nextSeed\`]) or \`false\` to terminate.
|
||
|
||
`,
|
||
comments: [`// [-10, -20, -30, -40, -50]`],
|
||
hash: '06e97ae5f0a22cf3c1400b8b9434078db0583e9507e74202eae98d9a59842f15'
|
||
},
|
||
union : {
|
||
description: `### union
|
||
|
||
Returns every element that exists in any of the two arrays once.
|
||
|
||
Create a \`Set\` with all values of \`a\` and \`b\` and convert to an array.
|
||
|
||
`,
|
||
comments: [`// [1,2,3,4]`],
|
||
hash: '279ee5619e2c8ab1ffd7723beb2d8925aab7d92198fbca786ba947fbaf00e497'
|
||
},
|
||
unionBy : {
|
||
description: `### unionBy
|
||
|
||
Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both.
|
||
|
||
Create a \`Set\` by applying all \`fn\` to all values of \`a\`.
|
||
Create a \`Set\` from \`a\` and all elements in \`b\` whose value, after applying \`fn\` does not match a value in the previously created set.
|
||
Return the last set converted to an array.
|
||
|
||
`,
|
||
comments: [`// [2.1, 1.2]`],
|
||
hash: 'a8f4f1c6141e9f86ff0cce30f10ab00266942965e63d1a93c1cd6626b7299c99'
|
||
},
|
||
unionWith : {
|
||
description: `### unionWith
|
||
|
||
Returns every element that exists in any of the two arrays once, using a provided comparator function.
|
||
|
||
Create a \`Set\` with all values of \`a\` and values in \`b\` for which the comparator finds no matches in \`a\`, using \`Array.findIndex()\`.
|
||
|
||
`,
|
||
comments: [`// [1, 1.2, 1.5, 3, 0, 3.9]`],
|
||
hash: '1b39e18064e94ecf8aac69882577c535783c923c0e1f1eeae01e22f2146db391'
|
||
},
|
||
uniqueElements : {
|
||
description: `### uniqueElements
|
||
|
||
Returns all unique values of an array.
|
||
|
||
Use ES6 \`Set\` and the \`...rest\` operator to discard all duplicated values.
|
||
|
||
`,
|
||
comments: [`// [1,2,3,4,5]`],
|
||
hash: '068991a0bfab1548f9ce09ca137bab9276a4432b5ebcbf3f934d8064a0f69af1'
|
||
},
|
||
untildify : {
|
||
description: `### untildify
|
||
|
||
Converts a tilde path to an absolute path.
|
||
|
||
Use \`String.replace()\` with a regular expression and \`OS.homedir()\` to replace the \`~\` in the start of the path with the home directory.
|
||
|
||
`,
|
||
comments: [`// '/Users/aUser/node'`],
|
||
hash: '66d31ebcaf10ed92736e0246d4ad3222a200086e27982bdb8aad76390c171aa0'
|
||
},
|
||
unzip : {
|
||
description: `### unzip
|
||
|
||
Creates an array of arrays, ungrouping the elements in an array produced by [zip](#zip).
|
||
|
||
Use \`Math.max.apply()\` to get the longest subarray in the array, \`Array.map()\` to make each element an array.
|
||
Use \`Array.reduce()\` and \`Array.forEach()\` to map grouped values to individual arrays.
|
||
|
||
`,
|
||
comments: [`//[['a', 'b'], [1, 2], [true, false]]`,`//[['a', 'b'], [1, 2], [true]]`],
|
||
hash: 'e571a886a0e18d46d1db9016b72bc9467ccbb3b4765a0b0f6a9f766bfddd1548'
|
||
},
|
||
unzipWith : {
|
||
description: `### unzipWith
|
||
|
||
Creates an array of elements, ungrouping the elements in an array produced by [zip](#zip) and applying the provided function.
|
||
|
||
Use \`Math.max.apply()\` to get the longest subarray in the array, \`Array.map()\` to make each element an array.
|
||
Use \`Array.reduce()\` and \`Array.forEach()\` to map grouped values to individual arrays.
|
||
Use \`Array.map()\` and the spread operator (\`...\`) to apply \`fn\` to each individual group of elements.
|
||
|
||
`,
|
||
comments: [`// [3, 30, 300]`],
|
||
hash: '846fa42e4c45d1fa850c7bb5b1dcbb56ea9ccffd80b2c4ca0220261834a3dfdf'
|
||
},
|
||
URLJoin : {
|
||
description: `### URLJoin
|
||
|
||
Joins all given URL segments together, then normalizes the resulting URL.
|
||
|
||
Use \`String.join('/')\` to combine URL segments, then a series of \`String.replace()\` calls with various regexps to normalize the resulting URL (remove double slashes, add proper slashes for protocol, remove slashes before parameters, combine parameters with \`'&'\` and normalize first parameter delimiter).
|
||
|
||
`,
|
||
comments: [`//, '$1://')`,`//www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'); // 'http://www.google.com/a/b/cd?foo=123&bar=foo'`],
|
||
hash: 'eae3f3e8b8b4693c85b4fd87719643257b6423de0a696f0890d2192dd004da9f'
|
||
},
|
||
UUIDGeneratorBrowser : {
|
||
description: `### UUIDGeneratorBrowser
|
||
|
||
Generates a UUID in a browser.
|
||
|
||
Use \`crypto\` API to generate a UUID, compliant with [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) version 4.
|
||
|
||
`,
|
||
comments: [`//www.ietf.org/rfc/rfc4122.txt) version 4.`,`// '7982fcfe-5721-4632-bede-6000885be57d'`],
|
||
hash: '21ad9afc423210d3e5cda9488c9eb9451c688ddfcc2c1d13cb8e1d545847a3fa'
|
||
},
|
||
UUIDGeneratorNode : {
|
||
description: `### UUIDGeneratorNode
|
||
|
||
Generates a UUID in Node.JS.
|
||
|
||
Use \`crypto\` API to generate a UUID, compliant with [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) version 4.
|
||
|
||
`,
|
||
comments: [`//www.ietf.org/rfc/rfc4122.txt) version 4.`,`// '79c7c136-60ee-40a2-beb2-856f1feabefc'`],
|
||
hash: '182beef816a0e70b7a4871450fb7e769b4fb1cc74ba15fd3e2374cb9f72bd040'
|
||
},
|
||
validateNumber : {
|
||
description: `### validateNumber
|
||
|
||
Returns \`true\` if the given value is a number, \`false\` otherwise.
|
||
|
||
Use \`!isNaN()\` in combination with \`parseFloat()\` to check if the argument is a number.
|
||
Use \`isFinite()\` to check if the number is finite.
|
||
Use \`Number()\` to check if the coercion holds.
|
||
|
||
`,
|
||
comments: [`// true`],
|
||
hash: 'ff17bb0d585271e5d73f9a2b87898dc032235bc42a7df2cf1a9ace87a2f9b019'
|
||
},
|
||
without : {
|
||
description: `### without
|
||
|
||
Filters out the elements of an array, that have one of the specified values.
|
||
|
||
Use \`Array.filter()\` to create an array excluding(using \`!Array.includes()\`) all given values.
|
||
|
||
_(For a snippet that mutates the original array see [\`pull\`](#pull))_
|
||
|
||
`,
|
||
comments: [`// [3]`],
|
||
hash: 'b972b3fd605305d820649c6b92aa1670ac07b363a1940b1635a4f070c9ab29c7'
|
||
},
|
||
words : {
|
||
description: `### words
|
||
|
||
Converts a given string into an array of words.
|
||
|
||
Use \`String.split()\` with a supplied pattern (defaults to non-alpha as a regexp) to convert to an array of strings. Use \`Array.filter()\` to remove any empty strings.
|
||
Omit the second argument to use the default regexp.
|
||
|
||
`,
|
||
comments: [`// ["I", "love", "javaScript"]`,`// ["python", "javaScript", "coffee"]`],
|
||
hash: '58d0cb51b8f6ca17a7eecf2baf2afb3f1d0e4e2677e986415bfb88eac9f138b0'
|
||
},
|
||
xProd : {
|
||
description: `### xProd
|
||
|
||
Creates a new array out of the two supplied by creating each possible pair from the arrays.
|
||
|
||
Use \`Array.reduce()\`, \`Array.map()\` and \`Array.concat()\` to produce every possible pair from the elements of the two arrays and save them in an array.
|
||
|
||
`,
|
||
comments: [`// [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]`],
|
||
hash: 'c62384cd9e707f9e26f711b02c53ce0805e675b8e521602fc8335e02c0cafba9'
|
||
},
|
||
yesNo : {
|
||
description: `### yesNo
|
||
|
||
Returns \`true\` if the string is \`y\`/\`yes\` or \`false\` if the string is \`n\`/\`no\`.
|
||
|
||
Use \`RegExp.test()\` to check if the string evaluates to \`y/yes\` or \`n/no\`.
|
||
Omit the second argument, \`def\` to set the default answer as \`no\`.
|
||
|
||
`,
|
||
comments: [`// true`,`// true`,`// false`,`// true`],
|
||
hash: '60e89489f96442e8b9094b70188f4cfbd37564efcee09ef9a82ecceacd2af815'
|
||
},
|
||
zip : {
|
||
description: `### zip
|
||
|
||
Creates an array of elements, grouped based on the position in the original arrays.
|
||
|
||
Use \`Math.max.apply()\` to get the longest array in the arguments.
|
||
Creates an array with that length as return value and use \`Array.from()\` with a map-function to create an array of grouped elements.
|
||
If lengths of the argument-arrays vary, \`undefined\` is used where no value could be found.
|
||
|
||
`,
|
||
comments: [`// [['a', 1, true], ['b', 2, false]]`,`// [['a', 1, true], [undefined, 2, false]]`],
|
||
hash: '97b639771737fb6d96e78b58cd4a63e3aa1379c83c1047e2d31389761b0178ef'
|
||
},
|
||
zipObject : {
|
||
description: `### zipObject
|
||
|
||
Given an array of valid property identifiers and an array of values, return an object associating the properties to the values.
|
||
|
||
Since an object can have undefined values but not undefined property pointers, the array of properties is used to decide the structure of the resulting object using \`Array.reduce()\`.
|
||
|
||
`,
|
||
comments: [`// {a: 1, b: 2, c: undefined}`,`// {a: 1, b: 2}`],
|
||
hash: '8bfb1ef93a51890298e9a688b2bebbb516707495be72929a2cbafc6c4dc1aa90'
|
||
},
|
||
zipWith : {
|
||
description: `### zipWith
|
||
|
||
Creates an array of elements, grouped based on the position in the original arrays and using function as the last value to specify how grouped values should be combined.
|
||
|
||
Check if the last argument provided in a function.
|
||
Use \`Math.max()\` to get the longest array in the arguments.
|
||
Creates an array with that length as return value and use \`Array.from()\` with a map-function to create an array of grouped elements.
|
||
If lengths of the argument-arrays vary, \`undefined\` is used where no value could be found.
|
||
The function is invoked with the elements of each group \`(...group)\`.
|
||
|
||
`,
|
||
comments: [`// [111,222]`,`// [111, 222, '3bc']`],
|
||
hash: '01892b8ea8d06d71e76f01679030ec1270ddc5a28fd4d872e1dcf0e356348a47'
|
||
}};
|