Consistent wording
This commit is contained in:
@ -5,7 +5,7 @@ tags: date,intermediate
|
|||||||
|
|
||||||
Calculates the date of `n` days from the given date, returning its string representation.
|
Calculates the date of `n` days from the given date, returning its string representation.
|
||||||
|
|
||||||
- Use `new Date()` to create a date object from the first parameter.
|
- Use `new Date()` to create a date object from the first argument.
|
||||||
- Use `Date.prototype.getDate()` and `Date.prototype.setDate()` to add `n` days to the given date.
|
- Use `Date.prototype.getDate()` and `Date.prototype.setDate()` to add `n` days to the given date.
|
||||||
- Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
|
- Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ tags: math,beginner
|
|||||||
Checks if two numbers are approximately equal to each other.
|
Checks if two numbers are approximately equal to each other.
|
||||||
|
|
||||||
- Use `Math.abs()` to compare the absolute difference of the two values to `epsilon`.
|
- Use `Math.abs()` to compare the absolute difference of the two values to `epsilon`.
|
||||||
- Omit the third parameter, `epsilon`, to use a default value of `0.001`.
|
- Omit the third argument, `epsilon`, to use a default value of `0.001`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const approximatelyEqual = (v1, v2, epsilon = 0.001) =>
|
const approximatelyEqual = (v1, v2, epsilon = 0.001) =>
|
||||||
|
|||||||
@ -17,6 +17,6 @@ const bifurcate = (arr, filter) =>
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]);
|
bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]);
|
||||||
// [ ['beep', 'boop', 'bar'], ['foo'] ]
|
// [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -17,5 +17,6 @@ const bifurcateBy = (arr, fn) =>
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
|
bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b');
|
||||||
|
// [ ['beep', 'boop', 'bar'], ['foo'] ]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -7,7 +7,7 @@ Capitalizes the first letter of a string.
|
|||||||
|
|
||||||
- Use array destructuring and `String.prototype.toUpperCase()` to capitalize the first letter of the string.
|
- 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.
|
- 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.
|
- Omit the `lowerRest` argument to keep the rest of the string intact, or set it to `true` to convert to lowercase.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const capitalize = ([first, ...rest], lowerRest = false) =>
|
const capitalize = ([first, ...rest], lowerRest = false) =>
|
||||||
|
|||||||
@ -5,7 +5,7 @@ tags: math,beginner
|
|||||||
|
|
||||||
Converts Celsius to Fahrenheit.
|
Converts Celsius to Fahrenheit.
|
||||||
|
|
||||||
- Follows the conversion formula `F = 1.8 * C + 32`.
|
- Follow the conversion formula `F = 1.8 * C + 32`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const celsiusToFahrenheit = degrees => 1.8 * degrees + 32;
|
const celsiusToFahrenheit = degrees => 1.8 * degrees + 32;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: checkProp
|
title: checkProp
|
||||||
tags: function,object,beginner
|
tags: function,object,intermediate
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a function that will invoke a predicate function for the specified property on a given object.
|
Creates a function that will invoke a predicate function for the specified property on a given object.
|
||||||
|
|||||||
@ -8,8 +8,8 @@ Creates a counter with the specified range, step and duration for the specified
|
|||||||
- Check if `step` has the proper sign and change it accordingly.
|
- Check if `step` has the proper sign and change it accordingly.
|
||||||
- Use `setInterval()` in combination with `Math.abs()` and `Math.floor()` to calculate the time between each new text draw.
|
- Use `setInterval()` in combination with `Math.abs()` and `Math.floor()` to calculate the time between each new text draw.
|
||||||
- Use `Document.querySelector()`, `Element.innerHTML` to update the value of the selected element.
|
- Use `Document.querySelector()`, `Element.innerHTML` to update the value of the selected element.
|
||||||
- Omit the fourth parameter, `step`, to use a default step of `1`.
|
- Omit the fourth argument, `step`, to use a default step of `1`.
|
||||||
- Omit the fifth parameter, `duration`, to use a default duration of `2000`ms.
|
- Omit the fifth argument, `duration`, to use a default duration of `2000`ms.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const counter = (selector, start, end, step = 1, duration = 2000) => {
|
const counter = (selector, start, end, step = 1, duration = 2000) => {
|
||||||
|
|||||||
@ -6,7 +6,7 @@ tags: date,beginner
|
|||||||
Gets the name of the weekday from a `Date` object.
|
Gets the name of the weekday from a `Date` object.
|
||||||
|
|
||||||
- Use `Date.prototype.toLocaleDateString()` with the `{ weekday: 'long' }` option to retrieve the weekday.
|
- Use `Date.prototype.toLocaleDateString()` with the `{ weekday: 'long' }` option to retrieve the weekday.
|
||||||
- Use the optional second parameter to get a language-specific name or omit it to use the default locale.
|
- Use the optional second argument to get a language-specific name or omit it to use the default locale.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const dayName = (date, locale) =>
|
const dayName = (date, locale) =>
|
||||||
|
|||||||
@ -6,7 +6,7 @@ tags: string,intermediate
|
|||||||
Decapitalizes the first letter of a string.
|
Decapitalizes the first letter of a string.
|
||||||
|
|
||||||
- Use array destructuring and `String.prototype.toLowerCase()` to decapitalize 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.toLowerCase()` to decapitalize first letter, `...rest` to get array of characters after first letter and then `Array.prototype.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.
|
- Omit the `upperRest` argument to keep the rest of the string intact, or set it to `true` to convert to uppercase.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const decapitalize = ([first, ...rest], upperRest = false) =>
|
const decapitalize = ([first, ...rest], upperRest = false) =>
|
||||||
|
|||||||
@ -6,6 +6,7 @@ tags: array,beginner
|
|||||||
Creates a new array with `n` elements removed from the left.
|
Creates a new array with `n` elements removed from the left.
|
||||||
|
|
||||||
- Use `Array.prototype.slice()` to remove the specified number of elements from the left.
|
- Use `Array.prototype.slice()` to remove the specified number of elements from the left.
|
||||||
|
- Omit the last argument, `n`, to use a default value of `1`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const drop = (arr, n = 1) => arr.slice(n);
|
const drop = (arr, n = 1) => arr.slice(n);
|
||||||
|
|||||||
@ -6,13 +6,14 @@ tags: array,beginner
|
|||||||
Creates a new array with `n` elements removed from the right.
|
Creates a new array with `n` elements removed from the right.
|
||||||
|
|
||||||
- Use `Array.prototype.slice()` to remove the specified number of elements from the right.
|
- Use `Array.prototype.slice()` to remove the specified number of elements from the right.
|
||||||
|
- Omit the last argument, `n`, to use a default value of `1`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const dropRight = (arr, n = 1) => arr.slice(0, -n);
|
const dropRight = (arr, n = 1) => arr.slice(0, -n);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
dropRight([1, 2, 3]); // [1,2]
|
dropRight([1, 2, 3]); // [1, 2]
|
||||||
dropRight([1, 2, 3], 2); // [1]
|
dropRight([1, 2, 3], 2); // [1]
|
||||||
dropRight([1, 2, 3], 42); // []
|
dropRight([1, 2, 3], 42); // []
|
||||||
```
|
```
|
||||||
|
|||||||
@ -5,7 +5,7 @@ tags: math,beginner
|
|||||||
|
|
||||||
Converts Fahrenheit to Celsius.
|
Converts Fahrenheit to Celsius.
|
||||||
|
|
||||||
- Follows the conversion formula `C = (F - 32) * 5/9`.
|
- Follow the conversion formula `C = (F - 32) * 5/9`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const fahrenheitToCelsius = degrees => (degrees - 32) * 5 / 9;
|
const fahrenheitToCelsius = degrees => (degrees - 32) * 5 / 9;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ tags: math,beginner
|
|||||||
Checks if the given number falls within the given range.
|
Checks if the given number falls within the given range.
|
||||||
|
|
||||||
- Use arithmetic comparison to check if the given number is in the specified 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`.
|
- If the second argument, `end`, is not specified, the range is considered to be from `0` to `start`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const inRange = (n, start, end = null) => {
|
const inRange = (n, start, end = null) => {
|
||||||
|
|||||||
@ -6,7 +6,7 @@ tags: string,beginner
|
|||||||
Indents each line in the provided string.
|
Indents each line in the provided string.
|
||||||
|
|
||||||
- Use `String.prototype.replace()` and a regular expression to add the character specified by `indent` `count` times at the start of each line.
|
- Use `String.prototype.replace()` and a regular expression to add the character specified by `indent` `count` times at the start of each line.
|
||||||
- Omit the third parameter, `indent`, to use a default indentation character of `' '`.
|
- Omit the third argument, `indent`, to use a default indentation character of `' '`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const indentString = (str, count, indent = ' ') =>
|
const indentString = (str, count, indent = ' ') =>
|
||||||
|
|||||||
@ -5,7 +5,7 @@ tags: math,beginner
|
|||||||
|
|
||||||
Converts kilometers to miles.
|
Converts kilometers to miles.
|
||||||
|
|
||||||
- Follows the conversion formula `mi = km * 0.621371`.
|
- Follow the conversion formula `mi = km * 0.621371`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const kmToMiles = km => km * 0.621371;
|
const kmToMiles = km => km * 0.621371;
|
||||||
|
|||||||
@ -5,7 +5,7 @@ tags: math,beginner
|
|||||||
|
|
||||||
Converts miles to kilometers.
|
Converts miles to kilometers.
|
||||||
|
|
||||||
- Follows the conversion formula `km = mi * 1.609344`.
|
- Follow the conversion formula `km = mi * 1.609344`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const milesToKm = miles => miles * 1.609344;
|
const milesToKm = miles => miles * 1.609344;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ tags: array,intermediate
|
|||||||
Returns the minimum/maximum value of an array, after applying the provided function to set the comparing rule.
|
Returns the minimum/maximum value of an array, after applying the provided function to set the comparing rule.
|
||||||
|
|
||||||
- Use `Array.prototype.reduce()` in combination with the `comparator` function to get the appropriate element in the array.
|
- Use `Array.prototype.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.
|
- Omit the second argument, `comparator`, to use the default one that returns the minimum element in the array.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const reduceWhich = (arr, comparator = (a, b) => a - b) =>
|
const reduceWhich = (arr, comparator = (a, b) => a - b) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user