Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"env": {
"test": {
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
"env": {
"test": {
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
}
}
}
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"plugins": ["jsdoc", "prefer-arrow","sonarjs"],
"plugins": ["jsdoc", "prefer-arrow", "sonarjs"],
"parserOptions": {
"sourceType": "module"
},
Expand Down Expand Up @@ -78,7 +78,6 @@
],
"camelcase": [2, { "properties": "never" }],


"prefer-arrow/prefer-arrow-functions": ["warn"],

"sonarjs/prefer-immediate-return": 0,
Expand Down
93 changes: 93 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"cspell": "^6.31.2",
"eslint": "^8.45.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-formatter-codeframe": "^7.32.1",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsdoc": "^46.4.4",
"eslint-plugin-prefer-arrow": "^1.2.3",
Expand Down
16 changes: 16 additions & 0 deletions src/difference/difference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const difference = (firstArray, secondArray) => {

let mySolution = [];
for (let myNum of firstArray) {
if (!secondArray.includes(myNum) && !mySolution.includes(myNum) ) {
mySolution.push(myNum) ;
}
}
return mySolution;
};

// export const difference = (firstArray, secondArray) => {
// const firstSet = new Set(firstArray);
// const secondSet = new Set(secondArray);
// return firstSet.filter((num) => !secondSet.has(num));
// };
24 changes: 24 additions & 0 deletions src/difference/difference.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { difference } from './difference.js';

describe('all the tests', () => {
it('works with no values in first array', () => {
expect(difference([], [1, 2, 3, 4, 5])).toEqual([]);
});
it('works with no values in second array', () => {
expect(difference([1, 2, 3, 4, 5], [])).toEqual([1, 2, 3, 4, 5]);
});
it('works with no values in either array', () => {
expect(difference([], [])).toEqual([]);
});
it('gives proper values for a basic non-repeating arrays', () => {
expect(difference([1, 2, 3, 11], [10, 11, 2, 4, 5])).toEqual([1, 3]);
});
it('works with repeated numbers in either array', () => {
expect(
difference(
[1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5],
[3, 3, 3, 3, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
),
).toEqual([5]);
});
});