diff --git a/snippets/bifurcate.md b/snippets/bifurcate.md index 5337e593c..be45bb12d 100644 --- a/snippets/bifurcate.md +++ b/snippets/bifurcate.md @@ -3,9 +3,10 @@ title: bifurcate tags: array,intermediate --- -Splits values into two groups. If an element in `filter` is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group. +Splits values into two groups, based on the result of the given `filter` array. - Use `Array.prototype.reduce()` and `Array.prototype.push()` to add elements to groups, based on `filter`. +- If `filter` has a truthy value for any element, add it to the first group, otherwise add it to the second group. ```js const bifurcate = (arr, filter) => @@ -13,5 +14,6 @@ const bifurcate = (arr, filter) => ``` ```js -bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ] +bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); +// [ ['beep', 'boop', 'bar'], ['foo'] ] ``` diff --git a/snippets/bifurcateBy.md b/snippets/bifurcateBy.md index 57f985e02..69b18ad35 100644 --- a/snippets/bifurcateBy.md +++ b/snippets/bifurcateBy.md @@ -3,9 +3,10 @@ title: bifurcateBy tags: array,intermediate --- -Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group. +Splits values into two groups, based on the result of the given filtering function. - Use `Array.prototype.reduce()` and `Array.prototype.push()` to add elements to groups, based on the value returned by `fn` for each element. +- If `fn` returns a truthy value for any element, add it to the first group, otherwise add it to the second group. ```js const bifurcateBy = (arr, fn) => diff --git a/snippets/binary.md b/snippets/binary.md index a69c18c51..a0e0ea44f 100644 --- a/snippets/binary.md +++ b/snippets/binary.md @@ -1,6 +1,6 @@ --- title: binary -tags: function,beginner +tags: function,intermediate --- Creates a function that accepts up to two arguments, ignoring any additional arguments. diff --git a/snippets/bind.md b/snippets/bind.md index 99abe53d2..4979178fe 100644 --- a/snippets/bind.md +++ b/snippets/bind.md @@ -1,15 +1,16 @@ --- title: bind -tags: function,object,intermediate +tags: function,object,advanced --- -Creates a function that invokes `fn` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments. +Creates a function that invokes `fn` with a given context, optionally prepending any additional supplied parameters to the arguments. - Return a `function` that uses `Function.prototype.apply()` to apply the given `context` to `fn`. -- Use `Array.prototype.concat()` to prepend any additional supplied parameters to the arguments. +- Use the spread operator (`...`) to prepend any additional supplied parameters to the arguments. ```js -const bind = (fn, context, ...boundArgs) => (...args) => fn.apply(context, [...boundArgs, ...args]); +const bind = (fn, context, ...boundArgs) => (...args) => + fn.apply(context, [...boundArgs, ...args]); ``` ```js diff --git a/snippets/bindAll.md b/snippets/bindAll.md index 62fddba76..e6ccb29a2 100644 --- a/snippets/bindAll.md +++ b/snippets/bindAll.md @@ -5,7 +5,8 @@ tags: object,function,intermediate Binds methods of an object to the object itself, overwriting the existing method. -- Use `Array.prototype.forEach()` to return a `function` that uses `Function.prototype.apply()` to apply the given context (`obj`) to `fn` for each function specified. +- Use `Array.prototype.forEach()` to iterate over the given `fns`. +- Return a function for each one, using `Function.prototype.apply()` to apply the given context (`obj`) to `fn`. ```js const bindAll = (obj, ...fns) => diff --git a/snippets/bindKey.md b/snippets/bindKey.md index 35678d31c..636c1f0f9 100644 --- a/snippets/bindKey.md +++ b/snippets/bindKey.md @@ -1,9 +1,9 @@ --- title: bindKey -tags: function,object,intermediate +tags: function,object,advanced --- -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. +Creates a function that invokes the method at a given key of an object, optionally prepending any additional supplied parameters to the arguments. - Return a `function` that uses `Function.prototype.apply()` to bind `context[fn]` to `context`. - Use the spread operator (`...`) to prepend any additional supplied parameters to the arguments. diff --git a/snippets/binomialCoefficient.md b/snippets/binomialCoefficient.md index 530d5df47..3e0267ea2 100644 --- a/snippets/binomialCoefficient.md +++ b/snippets/binomialCoefficient.md @@ -1,9 +1,9 @@ --- title: binomialCoefficient -tags: math,intermediate +tags: math,beginner --- -Evaluates the binomial coefficient of two integers `n` and `k`. +Calculates the number of ways to choose `k` items from `n` items without repetition and without order. - Use `Number.isNaN()` to check if any of the two values is `NaN`. - Check if `k` is less than `0`, greater than or equal to `n`, equal to `1` or `n - 1` and return the appropriate result. diff --git a/snippets/both.md b/snippets/both.md index c464cceb0..c8f9c0bdc 100644 --- a/snippets/both.md +++ b/snippets/both.md @@ -3,7 +3,7 @@ title: both tags: function,logic,beginner --- -Returns `true` if both functions return `true` for a given set of arguments, `false` otherwise. +Checks if both of the given functions return `true` for a given set of arguments. - Use the logical and (`&&`) operator on the result of calling the two functions with the supplied `args`. diff --git a/snippets/bottomVisible.md b/snippets/bottomVisible.md index 1120f3d58..ac6687743 100644 --- a/snippets/bottomVisible.md +++ b/snippets/bottomVisible.md @@ -1,9 +1,9 @@ --- title: bottomVisible -tags: browser,intermediate +tags: browser,beginner --- -Returns `true` if the bottom of the page is visible, `false` otherwise. +Checks if the bottom of the page is visible. - Use `scrollY`, `scrollHeight` and `clientHeight` to determine if the bottom of the page is visible. diff --git a/snippets/byteSize.md b/snippets/byteSize.md index 157211353..03ecf13e0 100644 --- a/snippets/byteSize.md +++ b/snippets/byteSize.md @@ -5,7 +5,8 @@ tags: string,beginner 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`. +- Convert a given string to a [`Blob` Object](https://developer.mozilla.org/en-US/docs/Web/API/Blob). +- Use `Blob.size` to get the length of the string in bytes. ```js const byteSize = str => new Blob([str]).size; diff --git a/snippets/call.md b/snippets/call.md index 00665b231..e8aea4468 100644 --- a/snippets/call.md +++ b/snippets/call.md @@ -1,11 +1,11 @@ --- title: call -tags: function,intermediate +tags: function,advanced --- -Given a key and a set of arguments, call them when given a context. Primarily useful in composition. +Given a key and a set of arguments, call them when given a context. -- Use a closure to call a stored key with stored arguments. +- Use a closure to call `key` with `args` for the given `context`. ```js const call = (key, ...args) => context => context[key](...args); diff --git a/snippets/capitalize.md b/snippets/capitalize.md index 33363b888..a8118dfbe 100644 --- a/snippets/capitalize.md +++ b/snippets/capitalize.md @@ -5,7 +5,8 @@ tags: string,intermediate Capitalizes the first letter of a string. -- Use array destructuring and `String.prototype.toUpperCase()` to capitalize first letter, `...rest` to get array of characters after first letter and then `Array.prototype.join('')` to make it a string again. +- Use array destructuring and `String.prototype.toUpperCase()` to capitalize the first letter of the string. +- Use `Array.prototype.join('')` to combine the capitalized `first` with the `...rest` of the characters. - Omit the `lowerRest` parameter to keep the rest of the string intact, or set it to `true` to convert to lowercase. ```js diff --git a/snippets/celsiusToFahrenheit.md b/snippets/celsiusToFahrenheit.md index cd324f749..fe29f227c 100644 --- a/snippets/celsiusToFahrenheit.md +++ b/snippets/celsiusToFahrenheit.md @@ -5,7 +5,7 @@ tags: math,beginner Converts Celsius to Fahrenheit. -- Follows the conversion formula `F = 1.8C + 32`. +- Follows the conversion formula `F = 1.8 * C + 32`. ```js const celsiusToFahrenheit = degrees => 1.8 * degrees + 32; diff --git a/snippets/checkProp.md b/snippets/checkProp.md index ba9437ae1..fcb7b6f30 100644 --- a/snippets/checkProp.md +++ b/snippets/checkProp.md @@ -3,9 +3,9 @@ title: checkProp tags: function,object,beginner --- -Given a `predicate` function and a `prop` string, this curried function will then take an `object` to inspect by calling the property and passing it to the predicate. +Creates a function that will invoke a predicate function for the specified property on a given object. -- Summon `prop` on `obj`, pass it to a provided `predicate` function and return a masked boolean. +- Return a curried function, that will invoke `predicate` for the specified `prop` on `obj` and return a boolean. ```js const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); diff --git a/snippets/coalesceFactory.md b/snippets/coalesceFactory.md index 8e0f964b5..1a7e1de90 100644 --- a/snippets/coalesceFactory.md +++ b/snippets/coalesceFactory.md @@ -1,17 +1,17 @@ --- title: coalesceFactory -tags: type,intermediate +tags: function,type,intermediate --- -Returns a customized coalesce function that returns the first argument that returns `true` from the provided argument validation function. +Customizes a coalesce function that returns the first argument which is true based on the given validator. -- Use `Array.prototype.find()` to return the first argument that returns `true` from the provided argument validation function. +- Use `Array.prototype.find()` to return the first argument that returns `true` from the provided argument validation function, `valid`. ```js const coalesceFactory = valid => (...args) => args.find(valid); ``` ```js -const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_)); -customCoalesce(undefined, null, NaN, '', 'Waldo'); // "Waldo" +const customCoalesce = coalesceFactory(v => ![null, undefined, '', NaN].includes(v)); +customCoalesce(undefined, null, NaN, '', 'Waldo'); // 'Waldo' ``` diff --git a/snippets/colorize.md b/snippets/colorize.md index 3f7f209ba..b0f81cc59 100644 --- a/snippets/colorize.md +++ b/snippets/colorize.md @@ -3,7 +3,7 @@ title: colorize tags: node,string,intermediate --- -Add special characters to text to print in color in the console (combined with `console.log()`). +Adds 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. diff --git a/snippets/compactWhitespace.md b/snippets/compactWhitespace.md index fb5cf37c4..5a6e9dbc8 100644 --- a/snippets/compactWhitespace.md +++ b/snippets/compactWhitespace.md @@ -3,7 +3,7 @@ title: compactWhitespace tags: string,regexp,beginner --- -Returns a string with whitespaces compacted. +Compacts whitespaces in a string. - Use `String.prototype.replace()` with a regular expression to replace all occurrences of 2 or more whitespace characters with a single space. diff --git a/snippets/containsWhitespace.md b/snippets/containsWhitespace.md index 819ab83d4..45e0e7998 100644 --- a/snippets/containsWhitespace.md +++ b/snippets/containsWhitespace.md @@ -3,7 +3,7 @@ title: containsWhitespace tags: string,regexp,beginner --- -Returns `true` if the given string contains any whitespace characters, `false` otherwise. +Checks if the given string contains any whitespace characters. - Use `RegExp.prototype.test()` with an appropriate regular expression to check if the given string contains any whitespace characters. diff --git a/snippets/converge.md b/snippets/converge.md index 17acb00b3..e727c8360 100644 --- a/snippets/converge.md +++ b/snippets/converge.md @@ -9,7 +9,8 @@ Accepts a converging function and a list of branching functions and returns a fu - Use the spread operator (`...`) to call `coverger` with the results of all other functions. ```js -const converge = (converger, fns) => (...args) => converger(...fns.map(fn => fn.apply(null, args))); +const converge = (converger, fns) => (...args) => + converger(...fns.map(fn => fn.apply(null, args))); ``` ```js diff --git a/snippets/copyToClipboard.md b/snippets/copyToClipboard.md index f9311c113..f63abf5e5 100644 --- a/snippets/copyToClipboard.md +++ b/snippets/copyToClipboard.md @@ -1,9 +1,9 @@ --- title: copyToClipboard -tags: browser,string,advanced +tags: browser,string,event,advanced --- -Copy a string to the clipboard. +Copies a string to the clipboard. Only works as a result of user action (i.e. inside a `click` event listener). - Create a new `