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
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"linebreak-style": [
"error",
"unix"
"windows"
],
"quotes": [
"error",
Expand Down Expand Up @@ -265,4 +265,4 @@
"never"
]
}
}
}
4 changes: 3 additions & 1 deletion Exercises/1-remove.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

const removeElement = (array, item) => {
// Remove item from array modifying original array
array.forEach((el, i) => {
if (el === item) array.splice(i, 1);
});
};

module.exports = { removeElement };
7 changes: 6 additions & 1 deletion Exercises/2-elements.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use strict';

const removeElements = (array, ...items) => {
// Remove multiple items from array modifying original array
items.forEach((el) => {
const idx = array.indexOf(el);
if (idx !== -1) array.splice(idx, 1);
});

return array;
};

module.exports = { removeElements };
8 changes: 4 additions & 4 deletions Exercises/3-unique.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

// Create and return a new array without duplicate elements
// Don't modify initial array

const unique = (array) => [];
const unique = (array) => {
const filtered = array.filter((el, i) => i === array.indexOf(el));
return filtered;
};

module.exports = { unique };
12 changes: 9 additions & 3 deletions Exercises/4-difference.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
'use strict';

// Find difference of two arrays
// elements from array1 that are not includes in array2

const difference = (array1, array2) => [];
const difference = (array1, array2) => {
const diffArr = [];

array1.forEach((el) => {
if (!array2.includes(el)) diffArr.push(el);
});

return diffArr;
};

module.exports = { difference };