From c221478e2d20c97efa41dba19ca53ea0faac71a9 Mon Sep 17 00:00:00 2001 From: 7assentlili Date: Mon, 4 Nov 2019 20:37:16 +0100 Subject: [PATCH 1/2] add includesAll --- snippets/includesAll.md | 17 +++++++++++++++++ test/includesAll.test.js | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 snippets/includesAll.md create mode 100644 test/includesAll.test.js diff --git a/snippets/includesAll.md b/snippets/includesAll.md new file mode 100644 index 000000000..f0afdceb9 --- /dev/null +++ b/snippets/includesAll.md @@ -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 +``` diff --git a/test/includesAll.test.js b/test/includesAll.test.js new file mode 100644 index 000000000..e36f9d93d --- /dev/null +++ b/test/includesAll.test.js @@ -0,0 +1,14 @@ +const {includesAll} = require('./_30s.js'); + +test('any is a Function', () => { + expect(includesAll).toBeInstanceOf(Function); +}); +test('Returns true when all values are included in arr', () => { + expect(includesAll([0, 1, 2, 3], [0, 1])).toBe(true); +}); +test('Returns false when one element fo values is not included in arr', () => { + expect(includesAll([0, 1, 2, 3], [1, 2, 4])).toBe(false); +}); +test('Returns false when values is larger than arr', () => { + expect(includesAll([0, 1, 2], [0, 1, 2, 3])).toBe(false); +}); From 690b1819951749cb71ac788585f3ada55493dbfb Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 5 Nov 2019 14:29:50 +0200 Subject: [PATCH 2/2] Update includesAll.md --- snippets/includesAll.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/includesAll.md b/snippets/includesAll.md index f0afdceb9..1bfe05973 100644 --- a/snippets/includesAll.md +++ b/snippets/includesAll.md @@ -3,7 +3,7 @@ title: includesAll tags: array,beginner --- -Returns `true` if all the elements of values are included in arr , `false` otherwise. +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`.