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: 3 additions & 1 deletion Exercises/1-remove.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';
// Remove item from array modifying original array

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

module.exports = { removeElement };

5 changes: 4 additions & 1 deletion Exercises/2-elements.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict';
// Remove multiple items from array modifying original array

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

module.exports = { removeElements };
6 changes: 5 additions & 1 deletion Exercises/3-unique.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// Create and return a new array without duplicate elements
// Don't modify initial array

const unique = array => [];
const unique = array => {
const newArr = [];
array.forEach(x => { if (!newArr.includes(x)) newArr.push(x); });
return newArr;
};

module.exports = { unique };
4 changes: 3 additions & 1 deletion Exercises/4-difference.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Find difference of two arrays
// elements from array1 that are not includes in array2

const difference = (array1, array2) => [];
const difference = (array1, array2) =>
//i'm here because of limit min, but may be it his wrong solution...
array1.filter(x => !array2.includes(x));

module.exports = { difference };