Add prototype to descriptions

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-10-20 11:21:07 +03:00
parent 920a0c390b
commit c3a2e47672
26 changed files with 26 additions and 26 deletions

View File

@ -6,7 +6,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 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. - Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
```js ```js

View File

@ -6,7 +6,7 @@ tags: date,intermediate
Calculates the date after adding the ginen number of business days. 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.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. - 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. - **NOTE:** Does not take official holidays into account.

View File

@ -5,7 +5,7 @@ tags: regexp,intermediate
Clones a regular expression. 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 ```js
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags); const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);

View File

@ -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.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`. - 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. - **NOTE:** Does not take official holidays into account.
```js ```js

View File

@ -5,7 +5,7 @@ tags: date,beginner
Calculates the date of `n` days ago from today as a string representation. 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. - Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
```js ```js

View File

@ -5,7 +5,7 @@ tags: date,beginner
Calculates the date of `n` days from today as a string representation. 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. - Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
```js ```js

View File

@ -5,7 +5,7 @@ tags: string,intermediate
Decapitalizes the first letter of a string. 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. - Omit the `upperRest` parameter to keep the rest of the string intact, or set it to `true` to convert to uppercase.
```js ```js

View File

@ -5,7 +5,7 @@ tags: object,array,type,advanced
Performs a deep comparison between two values to determine if they are equivalent. 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. - 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. - 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. - Use `Array.prototype.every()` to check if every key in `a` exists in `b` and if they are equivalent by calling `equals()` recursively.

View File

@ -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. 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. - 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. - Use `Array.prototype.filter()` to keep only those properties that are functions.
- Omit the second argument, `inherited`, to not include inherited properties by default. - Omit the second argument, `inherited`, to not include inherited properties by default.

View File

@ -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. - 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. - 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`. - 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. - Finally, use `Array.prototype.join()` to combine values in the array of `hexes` into a string.
```js ```js

View File

@ -5,7 +5,7 @@ tags: string,beginner
Indents each line in the provided string. 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 `' '`. - Omit the third parameter, `indent`, to use a default indentation character of `' '`.
```js ```js

View File

@ -5,7 +5,7 @@ tags: type,function,intermediate
Checks if the given argument is an `async` function. 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 ```js
const isAsyncFunction = val => const isAsyncFunction = val =>

View File

@ -5,7 +5,7 @@ tags: type,function,intermediate
Checks if the given argument is a generator function. 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 ```js
const isGeneratorFunction = val => const isGeneratorFunction = val =>

View File

@ -5,7 +5,7 @@ tags: string,beginner
Checks if a string is lower case. 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 ```js
const isLowerCase = str => str === str.toLowerCase(); const isLowerCase = str => str === str.toLowerCase();

View File

@ -5,7 +5,7 @@ tags: type,object,intermediate
Checks if the provided value is an object created by the Object constructor. 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 ```js
const isPlainObject = val => !!val && typeof val === 'object' && val.constructor === Object; const isPlainObject = val => !!val && typeof val === 'object' && val.constructor === Object;

View File

@ -6,7 +6,7 @@ tags: date,beginner
Results in a boolean representation of a specific date. Results in a boolean representation of a specific date.
- Pass the specific date object firstly. - 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 ```js
const isWeekday = (d = new Date()) => d.getDay() % 6 !== 0; const isWeekday = (d = new Date()) => d.getDay() % 6 !== 0;

View File

@ -6,7 +6,7 @@ tags: date,beginner
Results in a boolean representation of a specific date. Results in a boolean representation of a specific date.
- Pass the specific date object firstly. - 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 ```js
const isWeekend = (d = new Date()) => { const isWeekend = (d = new Date()) => {

View File

@ -6,7 +6,7 @@ tags: object,intermediate
Creates a new object from the specified object, where all the keys are in lowercase. 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. - 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 ```js
const lowercaseKeys = obj => const lowercaseKeys = obj =>

View File

@ -5,7 +5,7 @@ tags: object,intermediate
Compares two objects to determine if the first one contains equivalent property values to the second one. 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 ```js
const matches = (obj, source) => const matches = (obj, source) =>

View File

@ -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. 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. - If no function is provided, the values will be compared using the equality operator.
```js ```js

View File

@ -6,7 +6,7 @@ tags: string,math,advanced
Converts a number in bytes to a human-readable string. Converts a number in bytes to a human-readable string.
- Use an array dictionary of units to be accessed based on the exponent. - 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. - 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 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. - Omit the third argument, `addSpace`, to add space between the number and unit by default.

View File

@ -5,7 +5,7 @@ tags: string,beginner
Alphabetically sorts the characters in a string. 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 ```js
const sortCharactersInString = str => [...str].sort((a, b) => a.localeCompare(b)).join(''); const sortCharactersInString = str => [...str].sort((a, b) => a.localeCompare(b)).join('');

View File

@ -5,7 +5,7 @@ tags: function,intermediate
Iterates over a callback `n` times 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). - Omit the last argument, `context`, to use an `undefined` object (or the global object in non-strict mode).
```js ```js

View File

@ -5,7 +5,7 @@ tags: date,intermediate
Results in a string representation of tomorrow's date. 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. - Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
```js ```js

View File

@ -5,7 +5,7 @@ tags: string,regexp,intermediate
Returns `true` if the string is `y`/`yes` or `false` if the string is `n`/`no`. 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`. - Omit the second argument, `def` to set the default answer as `no`.
```js ```js

View File

@ -5,7 +5,7 @@ tags: date,intermediate
Results in a string representation of yesterday's date. 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. - Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
```js ```js