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

feat: add calculate median #73

Closed
wants to merge 2 commits into from

Conversation

syedjafer
Copy link

No description provided.

Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

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

Note: Sorting in O(n log n) is not the fastest approach.

@syedjafer syedjafer requested a review from appgurueu October 27, 2022 02:38

if (totalNumbers % 2 === 0){
let index = (totalNumbers) / 2;
return (sortedArray[index - 1] + sortedArray[index]) / 2;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return (sortedArray[index - 1] + sortedArray[index]) / 2;
return (numbers[index - 1] + numbers[index]) / 2;

The array name is numbers which is what I think you meant to use.

return (sortedArray[index - 1] + sortedArray[index]) / 2;
} else {
let index = (totalNumbers + 1) / 2;
return sortedArray[index - 1];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return sortedArray[index - 1];
return numbers[index - 1];

@raklaptudirm
Copy link
Member

#114 which is a superset of this, has been merged. Closing this pr.

@appgurueu
Copy link
Contributor

For the future, such "superset" PRs should maybe include a "closes ..." in their description so this happens automatically.

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.

3 participants