add includesAll

This commit is contained in:
7assentlili
2019-11-04 20:37:16 +01:00
parent 126a73e3b9
commit c221478e2d
2 changed files with 31 additions and 0 deletions

17
snippets/includesAll.md Normal file
View File

@ -0,0 +1,17 @@
---
title: includesAll
tags: array,beginner
---
Returns `true` if all the elements of 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
```