Files
30-seconds-of-code/snippets/includesAll.md
2019-11-05 14:29:50 +02:00

18 lines
446 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: includesAll
tags: array,beginner
---
Returns `true` if all the elements ιν `values` are included in `arr`, `false` otherwise.
Use `Array.prototype.every()` and `Array.prototype.includes()` to check if all elements of `values` are included in `arr`.
```js
const includesAll = (arr, values) => values.every(v => arr.includes(v));
```
```js
includesAll([1, 2, 3, 4], [1, 4]); // true
includesAll([1, 2, 3, 4], [1, 5]); // false
```