Files
30-seconds-of-code/snippets/similarity.md
Isabelle Viktoria Maciohsek 5cb69e3c5c Update snippet descriptions
2020-10-22 20:24:30 +03:00

18 lines
385 B
Markdown

---
title: similarity
tags: array,math,beginner
---
Returns an array of elements that appear in both arrays.
- Use `Array.prototype.includes()` to determine values that are not part of `values`.
- Use `Array.prototype.filter()` to remove them.
```js
const similarity = (arr, values) => arr.filter(v => values.includes(v));
```
```js
similarity([1, 2, 3], [1, 2, 4]); // [1, 2]
```