Skip to content
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

Pr 5 #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Pr 5 #5

wants to merge 2 commits into from

Conversation

CheezItMan
Copy link

This method determines if each element is unique.

});
});

return isAllUnique;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will return true when the array is empty

});
});

return isAllUnique;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job writing this algorithm. This would run but there might be way to find whether all elements in an array is unique a little more efficient by switching the isAllUnique to false when you find a duplicated value and end the iteration there instead of iterated through all elements of the array

let isAllUnique = true;

array.forEach((currentElement, currentIndex) => {
array.slice(currentIndex + 1).forEach((elementToCompare) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little complicated - consider removing the slice method entirely and just compare to the current element.

Copy link

@dev-elle-up dev-elle-up left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work getting this started.


array.forEach((currentElement, currentIndex) => {
array.slice(currentIndex + 1).forEach((elementToCompare) => {
if (elementToCompare === currentElement) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need to slice here. Can we remove it? I think the nested forEach will take care of comparing each element to the outer forEach element.

Copy link

@kanderson38 kanderson38 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it gets the job done, but we could make the syntax a little clearer. Also, should we write any tests for this function?

let isAllUnique = true;

array.forEach((currentElement, currentIndex) => {
array.slice(currentIndex + 1).forEach((elementToCompare) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax is a little confusing -- does it make more sense to compare currentElement to array[currentIndex + 1] instead of using array.slice(...).forEach(...)?

Copy link

@amythetester amythetester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All done for now.

@@ -0,0 +1,16 @@

const isAllUniqueElements = (array) => {
let isAllUnique = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to assign is AllUnique to something else. If the array is empty, it will evaluate to true.

@@ -0,0 +1,16 @@

const isAllUniqueElements = (array) => {
let isAllUnique = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check for if the array is empty and return appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants