480 B
480 B
title, type, language, tags, cover, dateModified
| title | type | language | tags | cover | dateModified | ||
|---|---|---|---|---|---|---|---|
| Array similarity | snippet | javascript |
|
dark-leaves-5 | 2020-10-22T20:24:30+03:00 |
Returns an array of elements that appear in both arrays.
- Use
Array.prototype.includes()to determine values that are not part ofvalues. - Use
Array.prototype.filter()to remove them.
const similarity = (arr, values) => arr.filter(v => values.includes(v));
similarity([1, 2, 3], [1, 2, 4]); // [1, 2]