Skip to content

London | 26-SDC-Jul | AYK | Sprint 1 | Analyse and Refactor Functions - #237

Open
sarawone wants to merge 4 commits into
CodeYourFuture:mainfrom
sarawone:AYK
Open

sarawone wants to merge 4 commits into
CodeYourFuture:mainfrom
sarawone:AYK

Conversation

@sarawone

@sarawone sarawone commented Oct 6, 2026

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1173

Changelist

I have chosen JavaScript as the programming language and refactored the code and commented in each file why the refactored code is better.
Please check and provide feedback ..

Thanks ..
AYK

@sarawone sarawone added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 6, 2026
// The refactor code ....
export function calculateSumAndProduct(numbers) {
let sum = 0;
let product =1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Spacing around = is inconsistent.

}


// This refactor code is better because it avoid to check every single item from two arrays for filter items & searching that each items includes in the second array .

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your complexity analysis is correct if the length of both arrays are $n$. What if their lengths are $n$ and $m$ respectively?

Also, your explanation does not quite explain how you derived the optimal complexity. Could you elaborate?

Comment on lines +28 to +44
export function hasPairWithSum(numbers,target){
const seen = new Set();

for (const num of numbers)
{
const needed = target-num;
if (seen.has(needed))
{
return true;
}
else
{
seen.add(num);
}
}

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • Why not use VS Code's "Format document" feature or any other formatting tool to keep the code consistently formatted?

  • The refactored code has a bug. Please fix it.

}


// The refactor code is better because it avoid nested loop but it create set so space complexity will be o(n). No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Saying "avoid nested loops" does not fully explain why the refactored implementation is better than the original. Instead, you could compare their time complexities to clearly explain the performance improvement.

On separate note, could you elaborate how you determined the complexity of the refactored implementation is $O(n)$?

}


//The refactor code is better because it avoid the nested for loop operation ....

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you also rephrase this statement to explain how you determine the complexity of the refactored code is $O(n)$?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants