Update formatting
This commit is contained in:
@ -7,7 +7,7 @@ lastUpdated: 2020-11-02T19:40:45+02:00
|
|||||||
|
|
||||||
Creates an array with the non-unique values filtered out.
|
Creates an array with the non-unique values filtered out.
|
||||||
|
|
||||||
- Use `new Set()` and the spread operator (`...`) to create an array of the unique values in `arr`.
|
- Use the `Set` constructor and the spread operator (`...`) to create an array of the unique values in `arr`.
|
||||||
- Use `Array.prototype.filter()` to create an array containing only the unique values.
|
- Use `Array.prototype.filter()` to create an array containing only the unique values.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-11-02T19:41:00+02:00
|
|||||||
|
|
||||||
Creates an array with the unique values filtered out.
|
Creates an array with the unique values filtered out.
|
||||||
|
|
||||||
- Use `new Set()` and the spread operator (`...`) to create an array of the unique values in `arr`.
|
- Use the `Set` constructor and the spread operator (`...`) to create an array of the unique values in `arr`.
|
||||||
- Use `Array.prototype.filter()` to create an array containing only the non-unique values.
|
- Use `Array.prototype.filter()` to create an array containing only the non-unique values.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-11T11:52:48+03:00
|
|||||||
|
|
||||||
Creates a frozen `Set` object.
|
Creates a frozen `Set` object.
|
||||||
|
|
||||||
- Use the `new Set()` constructor to create a new `Set` object from `iterable`.
|
- Use the `Set` constructor to create a new `Set` object from `iterable`.
|
||||||
- Set the `add`, `delete` and `clear` methods of the newly created object to `undefined`, so that they cannot be used, practically freezing the object.
|
- Set the `add`, `delete` and `clear` methods of the newly created object to `undefined`, so that they cannot be used, practically freezing the object.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-11T11:53:01+03:00
|
|||||||
|
|
||||||
Checks if the two iterables are disjointed (have no common values).
|
Checks if the two iterables are disjointed (have no common values).
|
||||||
|
|
||||||
- Use the `new Set()` constructor to create a new `Set` object from each iterable.
|
- Use the `Set` constructor to create a new `Set` object from each iterable.
|
||||||
- Use `Array.prototype.every()` and `Set.prototype.has()` to check that the two iterables have no common values.
|
- Use `Array.prototype.every()` and `Set.prototype.has()` to check that the two iterables have no common values.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:24:30+03:00
|
|||||||
|
|
||||||
Checks if the first iterable is a subset of the second one, excluding duplicate values.
|
Checks if the first iterable is a subset of the second one, excluding duplicate values.
|
||||||
|
|
||||||
- Use the `new Set()` constructor to create a new `Set` object from each iterable.
|
- Use the `Set` constructor to create a new `Set` object from each iterable.
|
||||||
- Use `Array.prototype.every()` and `Set.prototype.has()` to check that each value in the first iterable is contained in the second one.
|
- Use `Array.prototype.every()` and `Set.prototype.has()` to check that each value in the first iterable is contained in the second one.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:24:30+03:00
|
|||||||
|
|
||||||
Checks if the first iterable is a superset of the second one, excluding duplicate values.
|
Checks if the first iterable is a superset of the second one, excluding duplicate values.
|
||||||
|
|
||||||
- Use the `new Set()` constructor to create a new `Set` object from each iterable.
|
- Use the `Set` constructor to create a new `Set` object from each iterable.
|
||||||
- Use `Array.prototype.every()` and `Set.prototype.has()` to check that each value in the second iterable is contained in the first one.
|
- Use `Array.prototype.every()` and `Set.prototype.has()` to check that each value in the second iterable is contained in the first one.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:24:30+03:00
|
|||||||
|
|
||||||
Returns the symmetric difference between two arrays, without filtering out duplicate values.
|
Returns the symmetric difference between two arrays, without filtering out duplicate values.
|
||||||
|
|
||||||
- Create a `new Set()` from each array to get the unique values of each one.
|
- Create a `Set` from each array to get the unique values of each one.
|
||||||
- Use `Array.prototype.filter()` on each of them to only keep values not contained in the other.
|
- Use `Array.prototype.filter()` on each of them to only keep values not contained in the other.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:24:30+03:00
|
|||||||
|
|
||||||
Returns the symmetric difference between two arrays, after applying the provided function to each array element of both.
|
Returns the symmetric difference between two arrays, after applying the provided function to each array element of both.
|
||||||
|
|
||||||
- Create a `new Set()` from each array to get the unique values of each one after applying `fn` to them.
|
- Create a `Set` from each array to get the unique values of each one after applying `fn` to them.
|
||||||
- Use `Array.prototype.filter()` on each of them to only keep values not contained in the other.
|
- Use `Array.prototype.filter()` on each of them to only keep values not contained in the other.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:24:44+03:00
|
|||||||
|
|
||||||
Returns every element that exists in any of the two arrays at least once.
|
Returns every element that exists in any of the two arrays at least once.
|
||||||
|
|
||||||
- Create a `new Set()` with all values of `a` and `b` and convert it to an array.
|
- Create a `Set` with all values of `a` and `b` and convert it to an array.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const union = (a, b) => Array.from(new Set([...a, ...b]));
|
const union = (a, b) => Array.from(new Set([...a, ...b]));
|
||||||
|
|||||||
@ -7,8 +7,8 @@ lastUpdated: 2020-10-22T20:24:44+03:00
|
|||||||
|
|
||||||
Returns every element that exists in any of the two arrays at least once, after applying the provided function to each array element of both.
|
Returns every element that exists in any of the two arrays at least once, after applying the provided function to each array element of both.
|
||||||
|
|
||||||
- Create a `new Set()` by applying all `fn` to all values of `a`.
|
- Create a `Set` by applying all `fn` to all values of `a`.
|
||||||
- Create a `new Set()` from `a` and all elements in `b` whose value, after applying `fn` does not match a value in the previously created set.
|
- Create a `Set` from `a` and all elements in `b` whose value, after applying `fn` does not match a value in the previously created set.
|
||||||
- Return the last set converted to an array.
|
- Return the last set converted to an array.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:24:44+03:00
|
|||||||
|
|
||||||
Returns every element that exists in any of the two arrays at least once, using a provided comparator function.
|
Returns every element that exists in any of the two arrays at least once, using a provided comparator function.
|
||||||
|
|
||||||
- Create a `new Set()` with all values of `a` and values in `b` for which the comparator finds no matches in `a`, using `Array.prototype.findIndex()`.
|
- Create a `Set` with all values of `a` and values in `b` for which the comparator finds no matches in `a`, using `Array.prototype.findIndex()`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const unionWith = (a, b, comp) =>
|
const unionWith = (a, b, comp) =>
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:24:44+03:00
|
|||||||
|
|
||||||
Finds all unique values in an array.
|
Finds all unique values in an array.
|
||||||
|
|
||||||
- Create a `new Set()` from the given array to discard duplicated values.
|
- Create a `Set` from the given array to discard duplicated values.
|
||||||
- Use the spread operator (`...`) to convert it back to an array.
|
- Use the spread operator (`...`) to convert it back to an array.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -8,7 +8,7 @@ lastUpdated: 2020-10-22T20:24:44+03:00
|
|||||||
Returns the unique symmetric difference between two arrays, not containing duplicate values from either array.
|
Returns the unique symmetric difference between two arrays, not containing duplicate values from either array.
|
||||||
|
|
||||||
- Use `Array.prototype.filter()` and `Array.prototype.includes()` on each array to remove values contained in the other.
|
- Use `Array.prototype.filter()` and `Array.prototype.includes()` on each array to remove values contained in the other.
|
||||||
- Create a `new Set()` from the results, removing duplicate values.
|
- Create a `Set` from the results, removing duplicate values.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const uniqueSymmetricDifference = (a, b) => [
|
const uniqueSymmetricDifference = (a, b) => [
|
||||||
|
|||||||
Reference in New Issue
Block a user