Skip to content

Commit

Permalink
Merge pull request #7 from hckrnews/feature/array-with-object-diff
Browse files Browse the repository at this point in the history
Feature/array with object diff
  • Loading branch information
w3nl authored May 11, 2022
2 parents 6428ec2 + 468adcf commit cc0959c
Show file tree
Hide file tree
Showing 10 changed files with 3,379 additions and 5,075 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

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

steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 18
- run: npm ci
- run: npm test

Expand All @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build --if-present
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.14.0
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ dist: trusty
addons:
language: node_js
node_js:
- "10"
- "12"
- "14"
- "16"
- "18"
Expand Down
2 changes: 0 additions & 2 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module.exports = {

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

testURL: 'http://localhost/',

collectCoverage: true,
collectCoverageFrom: ['src/**/*.js'],
};
8,381 changes: 3,345 additions & 5,036 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hckrnews/arrays",
"version": "2.1.0",
"version": "2.1.1",
"description": "Usefull array helpers.",
"files": [
"src/helpers.js",
Expand All @@ -17,6 +17,7 @@
"src/modules/multisort.js",
"src/modules/random.js",
"src/modules/summ.js",
"src/modules/toJson.js",
"src/modules/unique.js",
"src/modules/update.js"
],
Expand Down Expand Up @@ -51,28 +52,28 @@
"vulnerabilities": "npm audit --only=prod"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/core": "^7.14.6",
"@babel/eslint-parser": "^7.14.7",
"@babel/plugin-transform-modules-commonjs": "^7.14.0",
"@babel/preset-env": "^7.12.1",
"@hckrnews/eslint-config": "^2.0.0",
"@jest/globals": "^27.0.6",
"babel-jest": "^27.0.6",
"@babel/plugin-transform-modules-commonjs": "^7.14.5",
"@babel/preset-env": "^7.14.7",
"@hckrnews/eslint-config": "^2.1.0",
"@jest/globals": "^28.1.0",
"babel-jest": "^28.1.0",
"codecov": "^3.8.1",
"coveralls": "^3.1.0",
"eslint": "^7.18.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint": "^8.3.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-html": "^6.1.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-prettier": "^4.0.0",
"esm": "^3.2.25",
"jest": "^27.0.6",
"prettier": "^2.2.0"
"jest": "^28.1.0",
"prettier": "^2.5.0"
},
"type": "module",
"engines": {
"node": ">= 10.13"
"node": ">= 14"
}
}
10 changes: 4 additions & 6 deletions src/modules/diff.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import toJson from './toJson.js';

class Diff {
constructor(currentArray, otherArray, total) {
this.currentArray = currentArray;
Expand All @@ -8,9 +10,7 @@ class Diff {
get differenceArray() {
return this.currentArray.filter(
(value) =>
this.otherArray
.map((item) => JSON.stringify(item))
.indexOf(JSON.stringify(value)) < 0
toJson(this.otherArray).indexOf(JSON.stringify(value)) < 0
);
}

Expand All @@ -21,9 +21,7 @@ class Diff {

return this.otherArray.filter(
(value) =>
this.currentArray
.map((item) => JSON.stringify(item))
.indexOf(JSON.stringify(value)) < 0
toJson(this.currentArray).indexOf(JSON.stringify(value)) < 0
);
}

Expand Down
24 changes: 11 additions & 13 deletions src/modules/intersect.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import toJson from './toJson.js';

export default function intersect(original, array, multi) {
return original.filter((value) => {
const jsonValue = toJson(array);

if (multi) {
const found = array
.map((item) => JSON.stringify(item))
.reduce((accumulator, currentValue) => {
if (currentValue.indexOf(JSON.stringify(value)) >= 0) {
return accumulator + 1;
}
const found = jsonValue.reduce((accumulator, currentValue) => {
if (currentValue.indexOf(JSON.stringify(value)) >= 0) {
return accumulator + 1;
}

return accumulator;
}, 0);
return accumulator;
}, 0);

return found === array.length;
}

return (
array
.map((item) => JSON.stringify(item))
.indexOf(JSON.stringify(value)) >= 0
);
return jsonValue.indexOf(JSON.stringify(value)) >= 0;
});
}
1 change: 1 addition & 0 deletions src/modules/toJson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default (items) => items.map((item) => JSON.stringify(item));

0 comments on commit cc0959c

Please sign in to comment.