-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
Conversation
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.
Note: Sorting in O(n log n) is not the fastest approach.
|
||
if (totalNumbers % 2 === 0){ | ||
let index = (totalNumbers) / 2; | ||
return (sortedArray[index - 1] + sortedArray[index]) / 2; |
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.
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]; |
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.
return sortedArray[index - 1]; | |
return numbers[index - 1]; |
#114 which is a superset of this, has been merged. Closing this pr. |
For the future, such "superset" PRs should maybe include a "closes ..." in their description so this happens automatically. |
No description provided.