-
-
Notifications
You must be signed in to change notification settings - Fork 50
Labs done #8
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?
Labs done #8
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,8 @@ | ||
'use strict'; | ||
|
||
const removeElement = (array, item) => { | ||
// Remove item from array modifying original array | ||
const index = array.indexOf(item); | ||
return index !== -1 ? array.splice(index, 1) : array; | ||
}; | ||
|
||
module.exports = { removeElement }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
'use strict'; | ||
|
||
const removeElements = (array, ...items) => { | ||
// Remove multiple items from array modifying original array | ||
for (const i of items) { | ||
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. Naming |
||
const index = array.indexOf(i); | ||
if (index !== -1) array.splice(index, 1); | ||
} | ||
return 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. No need to return, but it's ok. |
||
}; | ||
|
||
module.exports = { removeElements }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,12 @@ | |
// Create and return a new array without duplicate elements | ||
// Don't modify initial array | ||
|
||
const unique = array => []; | ||
const unique = array => { | ||
const arr = []; | ||
for (const item of 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. Use code block here. |
||
if (!arr.includes(item)) arr.push(item); | ||
return arr; | ||
}; | ||
|
||
module.exports = { unique }; | ||
|
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.
This task implies modifying original array, no need to return anything, but it's ok. Not ok is to use ternary here, if statement is more relevant for this case.