Skip to content

Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 | Analyse Refactor Functions - #239

Open
shreefAhmedM wants to merge 5 commits into
CodeYourFuture:mainfrom
shreefAhmedM:analyseRefactorFunctions
Open

shreefAhmedM wants to merge 5 commits into
CodeYourFuture:mainfrom
shreefAhmedM:analyseRefactorFunctions

Conversation

@shreefAhmedM

@shreefAhmedM shreefAhmedM commented Oct 12, 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

This PR analyses and refactors functions to improve efficiency, reduce time complexity, and follow best practices. It documents the original and optimised time and space complexities for each function.

@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 12, 2026
@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 12, 2026
@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM changed the title analyse and refactor sprint functions Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 1 |analyseRefactorFunctions Oct 12, 2026
@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 13, 2026

@illicitonion illicitonion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This generally looks good, but has a lot of lack of attention to detail - please take a look and fix up the comments

*/
export function calculateSumAndProduct(numbers) {
let sum = 0;
let product =1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This code isn't well formatted - it uses inconsistent spacing, and lines you added are missing trailing ; characters. Please fix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You haven't explained the complexity of the before or after code

* @returns {Array} Array containing unique common items
*
* Time Complexity: O(n * m)
* Space Complexity: O(u)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is u?


console.log(findCommonItems([2, 5, 7], [5, 6, 7]));

// Time:O(n \ m) filter() visits each item in the first array, and includes() may scan the second array each time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is n \ m?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

What is n \ m?

I updated the complexity; I did not intend to use k and u t, as it is different from my local update I pushed the changes. The new implementation improves the average time complexity from O(n × m) to O(n + m) by using a Set for faster lookups. The space complexity is O(n + m) because the code stores the second array’s items in a Set and creates the filtered results.

console.log(findCommonItems([2, 5, 7], [5, 6, 7]));

// Time:O(n \ m) filter() visits each item in the first array, and includes() may scan the second array each time.
// Sace: O(k) The Set stores unique common items, and the resulting array contains those items.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is k and how does it relate to the u you used above?

* Optimal Time Complexity:
*
* Time Complexity: O(N^2)
// Space Complexity: O(1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the space complexity O(1) both before and after your change?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Is the space complexity O(1) both before and after your change?

The original uses O(1) space and O(n²) time. The updated version uses O(n) space but improves the time to O(n) on average by using a Set for faster lookups.

@illicitonion illicitonion 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 13, 2026
@shreefAhmedM
shreefAhmedM deleted the analyseRefactorFunctions branch October 14, 2026 14:24
@shreefAhmedM
shreefAhmedM restored the analyseRefactorFunctions branch October 14, 2026 14:34
@shreefAhmedM shreefAhmedM reopened this Oct 14, 2026
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 1 |analyseRefactorFunctions Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 | Analyse Refactor Functions Oct 16, 2026
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants