From ea7c51ed7c4f0d9586ed55bd31e214ec80546a48 Mon Sep 17 00:00:00 2001 From: Danny Feliz Date: Mon, 11 Dec 2017 21:28:20 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Replace=20the=20usage=20of=20=C3=ACndexOf`?= =?UTF-8?q?=20for=20`includes`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9b166f0f6..eb2e006d0 100644 --- a/README.md +++ b/README.md @@ -109,11 +109,11 @@ var curry = f => ### Difference between arrays -Use `filter()` to remove values that are part of `values`, determined using `indexOf()`. +Use `filter()` to remove values that are part of `values`, determined using `includes()`. ```js var difference = (arr, values) => - arr.filter(v => values.indexOf(v) === -1); + arr.filter(v => !values.includes(v)); ``` ### Distance between two points @@ -315,11 +315,11 @@ var scrollToTop = _ => { ### Similarity between arrays -Use `filter()` to remove values that are not part of `values`, determined using `indexOf()`. +Use `filter()` to remove values that are not part of `values`, determined using `includes()`. ```js var difference = (arr, values) => - arr.filter(v => values.indexOf(v) !== -1); + arr.filter(v => values.includes(v)); ``` ### Sort characters in string (alphabetical) @@ -359,12 +359,12 @@ var tail = arr => arr.slice(1); ### Unique values of array Use `reduce()` to accumulate all unique values in an array. -Check if each value has already been added, using `indexOf()` on the accumulator array. +Check if each value has already been added, using `includes()` on the accumulator array. ```js var uniqueValues = arr => arr.reduce( (acc, val) => { - if(acc.indexOf(val) === -1) + if(acc.indexOf(val)) acc.push(val); return acc; }, []); From 08978c8b322194beb354a3b24dab4f323eec753b Mon Sep 17 00:00:00 2001 From: Danny Feliz Date: Mon, 11 Dec 2017 21:32:47 -0400 Subject: [PATCH 2/2] =?UTF-8?q?eplace=20the=20usage=20of=20=C3=ACndexOf`?= =?UTF-8?q?=20for=20`includes`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb2e006d0..4a3214633 100644 --- a/README.md +++ b/README.md @@ -364,7 +364,7 @@ Check if each value has already been added, using `includes()` on the accumulato ```js var uniqueValues = arr => arr.reduce( (acc, val) => { - if(acc.indexOf(val)) + if(!acc.includes(val)) acc.push(val); return acc; }, []);