From dcd3a7831659facd58f4fef24914decc36097b17 Mon Sep 17 00:00:00 2001 From: vreymond Date: Tue, 12 May 2020 08:40:35 +0200 Subject: [PATCH] Function - every and some functions --- collections/function/every-some-functions.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 collections/function/every-some-functions.md diff --git a/collections/function/every-some-functions.md b/collections/function/every-some-functions.md new file mode 100644 index 00000000..13ed8f53 --- /dev/null +++ b/collections/function/every-some-functions.md @@ -0,0 +1,15 @@ +~~~ javascript +const arr = [ 2, 28, 9, 1, 15 ]; +const arrBis = [ -5, 13, 26, 18, 12 ]; + +// Test function +const isPositive = (number) => number > 0; + +// Test if every element of array match the isPositive function +arr.every(isPositive); // -> true +arrBis.every(isPositive); // -> false + +// Test if some element of array match isPositive function +arr.some(isPositive); // -> true +arrBis.some(isPositive); // -> true +~~~