Travis build: 1374

This commit is contained in:
30secondsofcode
2018-01-24 10:54:56 +00:00
parent a415309748
commit 836ae3905b
3 changed files with 58 additions and 3 deletions

View File

@ -116,6 +116,8 @@ average(1, 2, 3);
* [`initializeArrayWithRangeRight`](#initializearraywithrangeright)
* [`initializeArrayWithValues`](#initializearraywithvalues)
* [`intersection`](#intersection)
* [`intersectionBy`](#intersectionby)
* [`intersectionWith`](#intersectionwith)
* [`isSorted`](#issorted)
* [`join`](#join)
* [`last`](#last)
@ -1179,6 +1181,53 @@ intersection([1, 2, 3], [4, 3, 2]); // [2,3]
<br>[⬆ Back to top](#table-of-contents)
### intersectionBy
Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both.
Create a `Set` by applying `fn` to all elements in `b`, then use `Array.filter()` on `a` to only keep elements, which produce values contained in `b` when `fn` is applied to them.
```js
const intersectionBy = (a, b, fn) => {
const s = new Set(b.map(x => fn(x)));
return a.filter(x => s.has(fn(x)));
};
```
<details>
<summary>Examples</summary>
```js
intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### intersectionWith
Returns a list of elements that exist in both arrays, using a provided comparator function.
Use `Array.filter()` and `Array.findIndex()` in combination with the provided comparator to determine intersecting values.
```js
const intersectionWith = (a, b, comp) => a.filter(x => b.findIndex(y => comp(x, y)) !== -1);
```
<details>
<summary>Examples</summary>
```js
intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1.5, 3, 0]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### isSorted
Returns `1` if the array is sorted in ascending order, `-1` if it is sorted in descending order or `0` if it is not sorted.

File diff suppressed because one or more lines are too long

View File

@ -5,8 +5,7 @@ Returns a list of elements that exist in both arrays, using a provided comparato
Use `Array.filter()` and `Array.findIndex()` in combination with the provided comparator to determine intersecting values.
```js
const intersectionWith = (a, b, comp) =>
a.filter(x => b.findIndex(y => comp(x, y)) !== -1);
const intersectionWith = (a, b, comp) => a.filter(x => b.findIndex(y => comp(x, y)) !== -1);
```
```js