Update snippet descriptions
This commit is contained in:
@ -3,7 +3,7 @@ title: addDaysToDate
|
||||
tags: date,intermediate
|
||||
---
|
||||
|
||||
Return the date of `n` days from the given date as a 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 `Date.getDate()` and `Date.setDate()` to add `n` days to the given date.
|
||||
|
||||
@ -3,7 +3,7 @@ title: addMultipleListeners
|
||||
tags: browser,event,intermediate
|
||||
---
|
||||
|
||||
Add multiple event listeners with the same handler to an element.
|
||||
Adds multiple event listeners with the same handler to an element.
|
||||
|
||||
- Use `Array.prototype.forEach()` and `EventTarget.addEventListener()` to add multiple event listeners with an assigned callback function to an element.
|
||||
|
||||
|
||||
@ -3,11 +3,12 @@ title: addWeekDays
|
||||
tags: date,intermediate
|
||||
---
|
||||
|
||||
Returns a date after adding given 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.prototype.reduce()` to iterate over the array, starting from `startDate` and incrementing, using `Date.getDate()` and `Date.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.
|
||||
|
||||
```js
|
||||
const addWeekDays = (startDate, count) =>
|
||||
|
||||
@ -3,7 +3,7 @@ title: all
|
||||
tags: array,beginner
|
||||
---
|
||||
|
||||
Returns `true` if the provided predicate function returns `true` for all elements in a collection, `false` otherwise.
|
||||
Checks if the provided predicate function returns `true` for all elements in a collection.
|
||||
|
||||
- Use `Array.prototype.every()` to test if all elements in the collection return `true` based on `fn`.
|
||||
- Omit the second argument, `fn`, to use `Boolean` as a default.
|
||||
|
||||
@ -3,7 +3,7 @@ title: allEqual
|
||||
tags: array,beginner
|
||||
---
|
||||
|
||||
Check if all elements in an array are equal.
|
||||
Checks if all elements in an array are equal.
|
||||
|
||||
- Use `Array.prototype.every()` to check if all the elements of the array are the same as the first one.
|
||||
- Elements in the array are compared using the strict comparison operator, which does not account for `NaN` self-inequality.
|
||||
|
||||
@ -3,7 +3,7 @@ title: and
|
||||
tags: math,logic,beginner
|
||||
---
|
||||
|
||||
Returns `true` if both arguments are `true`, `false` otherwise.
|
||||
Checks if both arguments are `true`.
|
||||
|
||||
- Use the logical and (`&&`) operator on the two given values.
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ title: any
|
||||
tags: array,beginner
|
||||
---
|
||||
|
||||
Returns `true` if the provided predicate function returns `true` for at least one element in a collection, `false` otherwise.
|
||||
Checks if the provided predicate function returns `true` for at least one element in a collection.
|
||||
|
||||
- Use `Array.prototype.some()` to test if any elements in the collection return `true` based on `fn`.
|
||||
- Omit the second argument, `fn`, to use `Boolean` as a default.
|
||||
|
||||
@ -3,9 +3,10 @@ title: aperture
|
||||
tags: array,intermediate
|
||||
---
|
||||
|
||||
Returns an array of `n`-tuples of consecutive elements.
|
||||
Creates an array of `n`-tuples of consecutive elements.
|
||||
|
||||
- Use `Array.prototype.slice()` and `Array.prototype.map()` to create an array of appropriate length and populate it with `n`-tuples of consecutive elements from `arr`.
|
||||
- Use `Array.prototype.slice()` and `Array.prototype.map()` to create an array of appropriate length.
|
||||
- Populate the array with `n`-tuples of consecutive elements from `arr`.
|
||||
- If `n` is greater than the length of `arr`, return an empty array.
|
||||
|
||||
```js
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: ary
|
||||
tags: function,intermediate
|
||||
tags: function,advanced
|
||||
---
|
||||
|
||||
Creates a function that accepts up to `n` arguments, ignoring any additional arguments.
|
||||
|
||||
@ -6,6 +6,7 @@ tags: function,intermediate
|
||||
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.
|
||||
- If the caught object is not an `Error`, use it to create a new `Error`.
|
||||
|
||||
```js
|
||||
const attempt = (fn, ...args) => {
|
||||
|
||||
@ -3,7 +3,7 @@ title: average
|
||||
tags: math,array,beginner
|
||||
---
|
||||
|
||||
Returns the average of two or more numbers.
|
||||
Calculates the average of two or more numbers.
|
||||
|
||||
- Use `Array.prototype.reduce()` to add each value to an accumulator, initialized with a value of `0`, divide by the `length` of the array.
|
||||
|
||||
|
||||
@ -3,9 +3,10 @@ title: averageBy
|
||||
tags: math,array,intermediate
|
||||
---
|
||||
|
||||
Returns the average of an array, after mapping each element to a value using the provided function.
|
||||
Calculates the average of an array, after mapping each element to a value using the provided function.
|
||||
|
||||
- Use `Array.prototype.map()` to map each element to the value returned by `fn`, `Array.prototype.reduce()` to add each value to an accumulator, initialized with a value of `0`, divide by the `length` of the array.
|
||||
- Use `Array.prototype.map()` to map each element to the value returned by `fn`.
|
||||
- Use `Array.prototype.reduce()` to add each value to an accumulator, initialized with a value of `0`, divide by the `length` of the array.
|
||||
|
||||
```js
|
||||
const averageBy = (arr, fn) =>
|
||||
|
||||
@ -8,6 +8,7 @@ Returns the weekday count 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.
|
||||
- **NOTE:** Does not take official holidays into account.
|
||||
|
||||
```js
|
||||
const countWeekDaysBetween = (startDate, endDate) =>
|
||||
|
||||
Reference in New Issue
Block a user