London | 25-SDC-July | Rihanna Poursoltani | Sprint 1 | Analyse and Refactor Functions#85
Open
RihannaP wants to merge 8 commits intoCodeYourFuture:mainfrom
Open
London | 25-SDC-July | Rihanna Poursoltani | Sprint 1 | Analyse and Refactor Functions#85RihannaP wants to merge 8 commits intoCodeYourFuture:mainfrom
RihannaP wants to merge 8 commits intoCodeYourFuture:mainfrom
Conversation
LonMcGregor
reviewed
Feb 11, 2026
LonMcGregor
left a comment
There was a problem hiding this comment.
Good work on these, you have found some good optimisations.
There are a few times you identify nested loops as o(n). If you have a nested loop, with the same array looping each time, are you sure it is going to be o(n)?
See also my other comment, there may be better ways to use sets in javascript.
| ]; | ||
| export const findCommonItems = (firstArray, secondArray) => { | ||
| const lookup = new Set(secondArray); | ||
| return [...new Set(firstArray.filter(item => lookup.has(item)))]; |
There was a problem hiding this comment.
Given you are using sets, are there any built-in methods that might help make this code even simpler?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Learners, PR Template
Self checklist
Changelist
I could understand code that most of them had complexity with nested loops. I refactored them by using Set and one loops to help complexity in both JS and PY.
Questions
No question