Skip to content

Commit cc0959c

Browse files
authored
Merge pull request #7 from hckrnews/feature/array-with-object-diff
Feature/array with object diff
2 parents 6428ec2 + 468adcf commit cc0959c

File tree

10 files changed

+3379
-5075
lines changed

10 files changed

+3379
-5075
lines changed

.github/workflows/nodejs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: [10.x, 12.x, 14.x, 16.x, 18.x]
12+
node-version: [14.x, 16.x, 18.x]
1313

1414
steps:
1515
- uses: actions/checkout@v1

.github/workflows/npm-publish.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v1
1616
with:
17-
node-version: 12
17+
node-version: 18
1818
- run: npm ci
1919
- run: npm test
2020

@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v2
2626
- uses: actions/setup-node@v1
2727
with:
28-
node-version: 12
28+
node-version: 18
2929
registry-url: https://registry.npmjs.org/
3030
- run: npm ci
3131
- run: npm run build --if-present

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.14.0

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ dist: trusty
33
addons:
44
language: node_js
55
node_js:
6-
- "10"
7-
- "12"
86
- "14"
97
- "16"
108
- "18"

jest.config.cjs

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ module.exports = {
1313

1414
testMatch: ['**/test/**/*.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'],
1515

16-
testURL: 'http://localhost/',
17-
1816
collectCoverage: true,
1917
collectCoverageFrom: ['src/**/*.js'],
2018
};

package-lock.json

+3,345-5,036
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hckrnews/arrays",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Usefull array helpers.",
55
"files": [
66
"src/helpers.js",
@@ -17,6 +17,7 @@
1717
"src/modules/multisort.js",
1818
"src/modules/random.js",
1919
"src/modules/summ.js",
20+
"src/modules/toJson.js",
2021
"src/modules/unique.js",
2122
"src/modules/update.js"
2223
],
@@ -51,28 +52,28 @@
5152
"vulnerabilities": "npm audit --only=prod"
5253
},
5354
"devDependencies": {
54-
"@babel/core": "^7.12.3",
55+
"@babel/core": "^7.14.6",
5556
"@babel/eslint-parser": "^7.14.7",
56-
"@babel/plugin-transform-modules-commonjs": "^7.14.0",
57-
"@babel/preset-env": "^7.12.1",
58-
"@hckrnews/eslint-config": "^2.0.0",
59-
"@jest/globals": "^27.0.6",
60-
"babel-jest": "^27.0.6",
57+
"@babel/plugin-transform-modules-commonjs": "^7.14.5",
58+
"@babel/preset-env": "^7.14.7",
59+
"@hckrnews/eslint-config": "^2.1.0",
60+
"@jest/globals": "^28.1.0",
61+
"babel-jest": "^28.1.0",
6162
"codecov": "^3.8.1",
6263
"coveralls": "^3.1.0",
63-
"eslint": "^7.18.0",
64-
"eslint-config-airbnb-base": "^14.2.1",
64+
"eslint": "^8.3.0",
65+
"eslint-config-airbnb-base": "^15.0.0",
6566
"eslint-config-prettier": "^8.1.0",
6667
"eslint-plugin-html": "^6.1.2",
6768
"eslint-plugin-import": "^2.22.1",
6869
"eslint-plugin-jsx-a11y": "^6.4.1",
69-
"eslint-plugin-prettier": "^3.3.1",
70+
"eslint-plugin-prettier": "^4.0.0",
7071
"esm": "^3.2.25",
71-
"jest": "^27.0.6",
72-
"prettier": "^2.2.0"
72+
"jest": "^28.1.0",
73+
"prettier": "^2.5.0"
7374
},
7475
"type": "module",
7576
"engines": {
76-
"node": ">= 10.13"
77+
"node": ">= 14"
7778
}
7879
}

src/modules/diff.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import toJson from './toJson.js';
2+
13
class Diff {
24
constructor(currentArray, otherArray, total) {
35
this.currentArray = currentArray;
@@ -8,9 +10,7 @@ class Diff {
810
get differenceArray() {
911
return this.currentArray.filter(
1012
(value) =>
11-
this.otherArray
12-
.map((item) => JSON.stringify(item))
13-
.indexOf(JSON.stringify(value)) < 0
13+
toJson(this.otherArray).indexOf(JSON.stringify(value)) < 0
1414
);
1515
}
1616

@@ -21,9 +21,7 @@ class Diff {
2121

2222
return this.otherArray.filter(
2323
(value) =>
24-
this.currentArray
25-
.map((item) => JSON.stringify(item))
26-
.indexOf(JSON.stringify(value)) < 0
24+
toJson(this.currentArray).indexOf(JSON.stringify(value)) < 0
2725
);
2826
}
2927

src/modules/intersect.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1+
import toJson from './toJson.js';
2+
13
export default function intersect(original, array, multi) {
24
return original.filter((value) => {
5+
const jsonValue = toJson(array);
6+
37
if (multi) {
4-
const found = array
5-
.map((item) => JSON.stringify(item))
6-
.reduce((accumulator, currentValue) => {
7-
if (currentValue.indexOf(JSON.stringify(value)) >= 0) {
8-
return accumulator + 1;
9-
}
8+
const found = jsonValue.reduce((accumulator, currentValue) => {
9+
if (currentValue.indexOf(JSON.stringify(value)) >= 0) {
10+
return accumulator + 1;
11+
}
1012

11-
return accumulator;
12-
}, 0);
13+
return accumulator;
14+
}, 0);
1315

1416
return found === array.length;
1517
}
1618

17-
return (
18-
array
19-
.map((item) => JSON.stringify(item))
20-
.indexOf(JSON.stringify(value)) >= 0
21-
);
19+
return jsonValue.indexOf(JSON.stringify(value)) >= 0;
2220
});
2321
}

src/modules/toJson.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default (items) => items.map((item) => JSON.stringify(item));

0 commit comments

Comments
 (0)