-
-
Notifications
You must be signed in to change notification settings - Fork 50
Tasks done #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Tasks done #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
'use strict'; | ||
|
||
const removeElement = (array, item) => { | ||
// Remove item from array modifying original array | ||
}; | ||
const removeElement = (array, item) => | ||
(array.includes(item) ? array.splice(array.indexOf(item), 1) : array); | ||
|
||
module.exports = { removeElement }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
'use strict'; | ||
|
||
const removeElements = (array, ...items) => { | ||
// Remove multiple items from array modifying original array | ||
for (const item of items) | ||
array.includes(item) ? array.splice(array.indexOf(item), 1) : array; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove ternary to improve readability. |
||
}; | ||
|
||
module.exports = { removeElements }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,14 @@ | |
// Create and return a new array without duplicate elements | ||
// Don't modify initial array | ||
|
||
const unique = array => []; | ||
const unique = array => { | ||
const na = []; | ||
|
||
array.forEach(i => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use for..of here, it's much faster and suitable in this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought I need to use Array functions mostly, so decided to use forEach |
||
if (!na.includes(i)) na.push(i); | ||
}); | ||
|
||
return na; | ||
}; | ||
|
||
module.exports = { unique }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,14 @@ | |
// Find difference of two arrays | ||
// elements from array1 that are not includes in array2 | ||
|
||
const difference = (array1, array2) => []; | ||
const difference = (array1, array2) => { | ||
const na = []; | ||
|
||
array1.forEach(i => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use for..of here. |
||
if (!array2.includes(i)) na.push(i); | ||
}); | ||
|
||
return na; | ||
}; | ||
|
||
module.exports = { difference }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove ternary to improve readability.