Difference between arrays
This commit is contained in:
10
README.md
10
README.md
@ -13,6 +13,7 @@
|
|||||||
* [Capitalize first letter](#capitalize-first-letter)
|
* [Capitalize first letter](#capitalize-first-letter)
|
||||||
* [Count occurences of a value in array](#count-occurences-of-a-value-in-array)
|
* [Count occurences of a value in array](#count-occurences-of-a-value-in-array)
|
||||||
* [Current URL](#current-url)
|
* [Current URL](#current-url)
|
||||||
|
* [Difference between arrays](#difference-between-arrays)
|
||||||
* [Distance between two points](#distance-between-two-points)
|
* [Distance between two points](#distance-between-two-points)
|
||||||
* [Even or odd number](#even-or-odd-number)
|
* [Even or odd number](#even-or-odd-number)
|
||||||
* [Factorial](#factorial)
|
* [Factorial](#factorial)
|
||||||
@ -86,6 +87,15 @@ Use `window.location.href` to get current URL.
|
|||||||
var currentUrl = _ => window.location.href;
|
var currentUrl = _ => window.location.href;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Difference between arrays
|
||||||
|
|
||||||
|
Use `filter()` to remove values that are not part of `values`, determined using `indexOf()`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
var difference = (arr, values) =>
|
||||||
|
arr.filter(v => values.indexOf(v) === -1);
|
||||||
|
```
|
||||||
|
|
||||||
### Distance between two points
|
### Distance between two points
|
||||||
|
|
||||||
Use `Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two points.
|
Use `Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two points.
|
||||||
|
|||||||
8
snippets/difference-between-arrays.md
Normal file
8
snippets/difference-between-arrays.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
### Difference between arrays
|
||||||
|
|
||||||
|
Use `filter()` to remove values that are not part of `values`, determined using `indexOf()`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
var difference = (arr, values) =>
|
||||||
|
arr.filter(v => values.indexOf(v) === -1);
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user