Add prototype to descriptions
This commit is contained in:
@ -6,7 +6,7 @@ tags: date,intermediate
|
||||
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 `Date.getDate()` and `Date.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.
|
||||
|
||||
```js
|
||||
|
||||
@ -6,7 +6,7 @@ tags: date,intermediate
|
||||
Calculates the date after adding the ginen number of business days.
|
||||
|
||||
- Use `Array.from()` to construct an array with `length` equal to the `count` of business days to be added.
|
||||
- Use `Array.prototype.reduce()` to iterate over the array, starting from `startDate` and incrementing, using `Date.getDate()` and `Date.setDate()`.
|
||||
- Use `Array.prototype.reduce()` to iterate over the array, starting from `startDate` and incrementing, using `Date.prototype.getDate()` and `Date.prototype.setDate()`.
|
||||
- If the current `date` is on a weekend, update it again by adding either one day or two days to make it a weekday.
|
||||
- **NOTE:** Does not take official holidays into account.
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ tags: regexp,intermediate
|
||||
|
||||
Clones a regular expression.
|
||||
|
||||
- Use `new RegExp()`, `RegExp.source` and `RegExp.flags` to clone the given regular expression.
|
||||
- Use `new RegExp()`, `RegExp.prototype.source` and `RegExp.prototype.flags` to clone the given regular expression.
|
||||
|
||||
```js
|
||||
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
||||
|
||||
@ -7,7 +7,7 @@ Counts the weekdays between two dates.
|
||||
|
||||
- Use `Array.from()` to construct an array with `length` equal to the number of days between `startDate` and `endDate`.
|
||||
- Use `Array.prototype.reduce()` to iterate over the array, checking if each date is a weekday and incrementing `count`.
|
||||
- Update `startDate` with the next day each loop using `Date.getDate()` and `Date.setDate()` to advance it by one day.
|
||||
- Update `startDate` with the next day each loop using `Date.prototype.getDate()` and `Date.prototype.setDate()` to advance it by one day.
|
||||
- **NOTE:** Does not take official holidays into account.
|
||||
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@ tags: date,beginner
|
||||
|
||||
Calculates the date of `n` days ago from today as a string representation.
|
||||
|
||||
- Use `new Date()` to get the current date, `Math.abs()` and `Date.getDate()` to update the date accordingly and set to the result using `Date.setDate()`.
|
||||
- Use `new Date()` to get the current date, `Math.abs()` and `Date.prototype.getDate()` to update the date accordingly and set to the result using `Date.prototype.setDate()`.
|
||||
- Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
|
||||
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@ tags: date,beginner
|
||||
|
||||
Calculates the date of `n` days from today as a string representation.
|
||||
|
||||
- Use `new Date()` to get the current date, `Math.abs()` and `Date.getDate()` to update the date accordingly and set to the result using `Date.setDate()`.
|
||||
- Use `new Date()` to get the current date, `Math.abs()` and `Date.prototype.getDate()` to update the date accordingly and set to the result using `Date.prototype.setDate()`.
|
||||
- Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
|
||||
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@ tags: string,intermediate
|
||||
|
||||
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.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.
|
||||
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@ tags: object,array,type,advanced
|
||||
|
||||
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 the two values are identical, if they are both `Date` objects with the same time, using `Date.prototype.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.
|
||||
- Use `Array.prototype.every()` to check if every key in `a` exists in `b` and if they are equivalent by calling `equals()` recursively.
|
||||
|
||||
@ -6,7 +6,7 @@ tags: object,function,advanced
|
||||
Gets 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.
|
||||
- If `inherited` is `true`, use `Object.getPrototypeOf(obj)` to also get the object's inherited properties.
|
||||
- Use `Array.prototype.filter()` to keep only those properties that are functions.
|
||||
- Omit the second argument, `inherited`, to not include inherited properties by default.
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ 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.
|
||||
- Create a new `TextEncoder` and use it to encode `val`, passing its value to `SubtleCrypto.digest()` to generate a digest of the given data.
|
||||
- Use `DataView.prototype.getUint32()` to read data from the resolved `ArrayBuffer`.
|
||||
- Add the data to an array using `Array.prototype.push()` after converting it to its hexadecimal representation using `Number.toString(16)`.
|
||||
- Add the data to an array using `Array.prototype.push()` after converting it to its hexadecimal representation using `Number.prototype.toString(16)`.
|
||||
- Finally, use `Array.prototype.join()` to combine values in the array of `hexes` into a string.
|
||||
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@ tags: string,beginner
|
||||
|
||||
Indents each line in the provided string.
|
||||
|
||||
- Use `String.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 `' '`.
|
||||
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@ tags: type,function,intermediate
|
||||
|
||||
Checks if the given argument is an `async` function.
|
||||
|
||||
- Use `Object.prototype.toString()` and `Function.call()` and check if the result is `'[object AsyncFunction]'`.
|
||||
- Use `Object.prototype.toString()` and `Function.prototype.call()` and check if the result is `'[object AsyncFunction]'`.
|
||||
|
||||
```js
|
||||
const isAsyncFunction = val =>
|
||||
|
||||
@ -5,7 +5,7 @@ tags: type,function,intermediate
|
||||
|
||||
Checks if the given argument is a generator function.
|
||||
|
||||
- Use `Object.prototype.toString()` and `Function.call()` and check if the result is `'[object GeneratorFunction]'`.
|
||||
- Use `Object.prototype.toString()` and `Function.prototype.call()` and check if the result is `'[object GeneratorFunction]'`.
|
||||
|
||||
```js
|
||||
const isGeneratorFunction = val =>
|
||||
|
||||
@ -5,7 +5,7 @@ tags: string,beginner
|
||||
|
||||
Checks if a string is lower case.
|
||||
|
||||
- Convert the given string to lower case, using `String.toLowerCase()` and compare it to the original.
|
||||
- Convert the given string to lower case, using `String.prototype.toLowerCase()` and compare it to the original.
|
||||
|
||||
```js
|
||||
const isLowerCase = str => str === str.toLowerCase();
|
||||
|
||||
@ -5,7 +5,7 @@ tags: type,object,intermediate
|
||||
|
||||
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`.
|
||||
- Check if the provided value is truthy, use `typeof` to check if it is an object and `Object.prototype.constructor` to make sure the constructor is equal to `Object`.
|
||||
|
||||
```js
|
||||
const isPlainObject = val => !!val && typeof val === 'object' && val.constructor === Object;
|
||||
|
||||
@ -6,7 +6,7 @@ tags: date,beginner
|
||||
Results in a boolean representation of a specific date.
|
||||
|
||||
- Pass the specific date object firstly.
|
||||
- Use `Date.getDay()` to check weekday by using a modulo operator and then returning a boolean.
|
||||
- Use `Date.prototype.getDay()` to check weekday by using a modulo operator and then returning a boolean.
|
||||
|
||||
```js
|
||||
const isWeekday = (d = new Date()) => d.getDay() % 6 !== 0;
|
||||
|
||||
@ -6,7 +6,7 @@ tags: date,beginner
|
||||
Results in a boolean representation of a specific date.
|
||||
|
||||
- Pass the specific date object firstly.
|
||||
- Use `Date.getDay()` to check weekend based on the day being returned as 0 - 6 using a modulo operation then return a boolean.
|
||||
- Use `Date.prototype.getDay()` to check weekend based on the day being returned as 0 - 6 using a modulo operation then return a boolean.
|
||||
|
||||
```js
|
||||
const isWeekend = (d = new Date()) => {
|
||||
|
||||
@ -6,7 +6,7 @@ tags: object,intermediate
|
||||
Creates a new object from the specified object, where all the keys are in lowercase.
|
||||
|
||||
- Use `Object.keys()` and `Array.prototype.reduce()` to create a new object from the specified object.
|
||||
- Convert each key in the original object to lowercase, using `String.toLowerCase()`.
|
||||
- Convert each key in the original object to lowercase, using `String.prototype.toLowerCase()`.
|
||||
|
||||
```js
|
||||
const lowercaseKeys = obj =>
|
||||
|
||||
@ -5,7 +5,7 @@ tags: object,intermediate
|
||||
|
||||
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.prototype.every()`, `Object.hasOwnProperty()` and strict comparison to determine if all keys exist in the first object and have the same values.
|
||||
- Use `Object.keys(source)` to get all the keys of the second object, then `Array.prototype.every()`, `Object.prototype.hasOwnProperty()` and strict comparison to determine if all keys exist in the first object and have the same values.
|
||||
|
||||
```js
|
||||
const matches = (obj, source) =>
|
||||
|
||||
@ -5,7 +5,7 @@ tags: object,intermediate
|
||||
|
||||
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.prototype.every()`, `Object.hasOwnProperty()` and the provided function to determine if all keys exist in the first object and have equivalent values.
|
||||
- Use `Object.keys(source)` to get all the keys of the second object, then `Array.prototype.every()`, `Object.prototype.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.
|
||||
|
||||
```js
|
||||
|
||||
@ -6,7 +6,7 @@ tags: string,math,advanced
|
||||
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.
|
||||
- Use `Number.prototype.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.
|
||||
|
||||
@ -5,7 +5,7 @@ tags: string,beginner
|
||||
|
||||
Alphabetically sorts the characters in a string.
|
||||
|
||||
- Use the spread operator (`...`), `Array.prototype.sort()` and `String.localeCompare()` to sort the characters in `str`, recombine using `String.prototype.join('')`.
|
||||
- Use the spread operator (`...`), `Array.prototype.sort()` and `String.prototype.localeCompare()` to sort the characters in `str`, recombine using `String.prototype.join('')`.
|
||||
|
||||
```js
|
||||
const sortCharactersInString = str => [...str].sort((a, b) => a.localeCompare(b)).join('');
|
||||
|
||||
@ -5,7 +5,7 @@ tags: function,intermediate
|
||||
|
||||
Iterates over a callback `n` times
|
||||
|
||||
- Use `Function.call()` to call `fn` `n` times or until it returns `false`.
|
||||
- Use `Function.prototype.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).
|
||||
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@ tags: date,intermediate
|
||||
|
||||
Results in a string representation of tomorrow's date.
|
||||
|
||||
- Use `new Date()` to get the current date, increment by one using `Date.getDate()` and set the value to the result using `Date.setDate()`.
|
||||
- Use `new Date()` to get the current date, increment by one using `Date.prototype.getDate()` and set the value to the result using `Date.prototype.setDate()`.
|
||||
- Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
|
||||
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@ tags: string,regexp,intermediate
|
||||
|
||||
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`.
|
||||
- Use `RegExp.prototype.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`.
|
||||
|
||||
```js
|
||||
|
||||
@ -5,7 +5,7 @@ tags: date,intermediate
|
||||
|
||||
Results in a string representation of yesterday's date.
|
||||
|
||||
- Use `new Date()` to get the current date, decrement by one using `Date.getDate()` and set the value to the result using `Date.setDate()`.
|
||||
- Use `new Date()` to get the current date, decrement by one using `Date.prototype.getDate()` and set the value to the result using `Date.prototype.setDate()`.
|
||||
- Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user