-
-
Notifications
You must be signed in to change notification settings - Fork 50
Exercises completed #7
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?
Changes from 4 commits
d37dcde
83f978b
1af453d
f5f4ff4
452318c
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,8 @@ | ||
'use strict'; | ||
|
||
const removeElement = (array, item) => { | ||
// Remove item from array modifying original array | ||
const index = array.indexOf(item); | ||
index > -1 ? array.splice(index, 1) : array; | ||
}; | ||
|
||
module.exports = { removeElement }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
'use strict'; | ||
|
||
const removeElements = (array, ...items) => { | ||
// Remove multiple items from array modifying original array | ||
for (const item of items) { | ||
const index = array.indexOf(item); | ||
index > -1 ? array.splice(index, 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. Ditto 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. Done. |
||
} | ||
}; | ||
|
||
module.exports = { removeElements }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
'use strict'; | ||
|
||
// Create and return a new array without duplicate elements | ||
// Don't modify initial array | ||
|
||
const unique = array => []; | ||
const unique = array => { | ||
const newArray = []; | ||
for (const item of array) { | ||
!newArray.includes(item) ? newArray.push(item) : 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. Ditto 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. Done. |
||
} | ||
return newArray; | ||
}; | ||
|
||
module.exports = { unique }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
'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 newArray = []; | ||
for (const item of array1) { | ||
!array2.includes(item) ? newArray.push(item) : 0; | ||
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. Ditto 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. Done. |
||
} | ||
return newArray; | ||
}; | ||
|
||
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.
Use if statement instead
Uh oh!
There was an error while loading. Please reload this page.
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.
Thank you!
Done.