Skip to content

Commit bcceca1

Browse files
authored
Merge pull request #9 from hckrnews/feature/array-with-object-diff
Finetune dif and intersect
2 parents cc0959c + 4151c51 commit bcceca1

File tree

5 files changed

+63
-64
lines changed

5 files changed

+63
-64
lines changed

package-lock.json

+57-57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hckrnews/arrays",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "Usefull array helpers.",
55
"files": [
66
"src/helpers.js",

src/modules/diff.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class Diff {
99

1010
get differenceArray() {
1111
return this.currentArray.filter(
12-
(value) =>
13-
toJson(this.otherArray).indexOf(JSON.stringify(value)) < 0
12+
(value) => !toJson(this.otherArray).includes(JSON.stringify(value))
1413
);
1514
}
1615

@@ -21,7 +20,7 @@ class Diff {
2120

2221
return this.otherArray.filter(
2322
(value) =>
24-
toJson(this.currentArray).indexOf(JSON.stringify(value)) < 0
23+
!toJson(this.currentArray).includes(JSON.stringify(value))
2524
);
2625
}
2726

src/modules/intersect.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function intersect(original, array, multi) {
66

77
if (multi) {
88
const found = jsonValue.reduce((accumulator, currentValue) => {
9-
if (currentValue.indexOf(JSON.stringify(value)) >= 0) {
9+
if (currentValue.includes(JSON.stringify(value))) {
1010
return accumulator + 1;
1111
}
1212

@@ -16,6 +16,6 @@ export default function intersect(original, array, multi) {
1616
return found === array.length;
1717
}
1818

19-
return jsonValue.indexOf(JSON.stringify(value)) >= 0;
19+
return jsonValue.includes(JSON.stringify(value));
2020
});
2121
}

src/modules/multifilter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Match {
99

1010
check(value) {
1111
if (Array.isArray(this.find)) {
12-
return this.checkOperators(value, this.find.indexOf(value) < 0);
12+
return this.checkOperators(value, !this.find.includes(value));
1313
}
1414

1515
return this.checkOperators(value, String(value) !== String(this.find));

0 commit comments

Comments
 (0)