-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: master
Are you sure you want to change the base?
Pr 5 #5
Changes from 1 commit
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
const isAllUniqueElements = (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. Could we rename to areAllElementsUnique? Might read a little more smoothly ... |
||
let isAllUnique = true; | ||
|
||
array.forEach((currentElement, currentIndex) => { | ||
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. good function to check for unique elements |
||
array.slice(currentIndex + 1).forEach((elementToCompare) => { | ||
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. Consider limiting the number of loops within loops to improve time efficiency |
||
if (elementToCompare === currentElement) { | ||
isAllUnique = false; | ||
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 feel like we should be returning isAllUnique right away if it is false so that the code doesn't have to continue through the entire array before returning. 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. You may want to consider exiting loop if isAllUnique==false. Otherwise, it will loop through the whole 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. Returns true for empty array -- should it return null instead? 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. If you add a return as soon as you find a duplicate, it will be more efficient because it won't have to keep searching through the rest of the 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. We can add a return if isAllUnique = false instead to make the program run more efficiently 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. Can we refactor to exit the loop as soon as it is false? |
||
} | ||
}); | ||
}); | ||
|
||
return isAllUnique; | ||
}; | ||
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. Nice easy-to-read function |
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.
Add a comment to describe what type of uniqueness you are looking for (unique characters? unique array items?)