Repository navigation
London | 26-ITP-Sep | Mahir Shah | Sprint 1 | Data Groups #1481
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
Open
MahirShah300
wants to merge
23
commits into
CodeYourFuture:main
Choose a base branch
from
MahirShah300:Sprint-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
42e6670
Fix calculateMedian function, Implement error checking
MahirShah300 b20550f
Implement tests
MahirShah300 6af26a2
Implement findMax function
MahirShah300 7a3e4e5
Add tests
MahirShah300 36a519d
Fix error tests
MahirShah300 e97ee71
Fix error tests
MahirShah300 57f2875
Implement sum function
MahirShah300 1b7b599
Add tests
MahirShah300 479a30c
Implement dedupe function
MahirShah300 42bdd8d
Add tests
MahirShah300 03f21b0
Implement calculateMean function
MahirShah300 4d19b02
Add tests
MahirShah300 c3a4ffa
Implement describeMedian function
MahirShah300 8133c48
Refactor includes function to use for...of loop
MahirShah300 01acd63
Change name of currentValue to value. Add check to see if number is f…
MahirShah300 d166d5f
Made value in for loop const
MahirShah300 3ff7bca
Add check that the returned array is a copy and not the same array
MahirShah300 ca33de5
Simplify try catch to use thrown error message
MahirShah300 d4abcdf
Use more efficient method to find max element
MahirShah300 45748c8
Add check for infinite values. Use exported sum function from sum.js
MahirShah300 2d78b20
Correct decimal sum test to use toBeCloseTo
MahirShah300 60a8cf4
Declared loop variable const
MahirShah300 709eeb8
Change currentValue to value. Add check for infinite
MahirShah300 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,12 @@ | ||
| function dedupe() {} | ||
| function dedupe(elements) { | ||
| const dedupedArray = []; | ||
|
|
||
| for (const value of elements) { | ||
| if (!dedupedArray.includes(value)) { | ||
| dedupedArray.push(value); | ||
| } | ||
| } | ||
| return dedupedArray; | ||
| } | ||
|
|
||
| module.exports = dedupe; |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,22 @@ | ||
| function findMax(elements) { | ||
| if (!Array.isArray(elements)) { | ||
| throw new Error("findMax requires an array of numbers"); | ||
| } | ||
|
|
||
| if (elements.length === 0) { | ||
| return -Infinity; | ||
| } | ||
|
|
||
| if ( | ||
| !elements.every( | ||
| (currentValue) => | ||
| typeof currentValue === "number" && !Number.isNaN(currentValue) | ||
| ) | ||
| ) { | ||
| throw new Error("findMax requires an array of numbers"); | ||
| } | ||
|
|
||
| return Math.max(...elements); | ||
| } | ||
|
|
||
| module.exports = findMax; |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,29 @@ | ||
| function calculateMean(list) {} | ||
| const sum = require("./sum.js"); | ||
|
|
||
| function calculateMean(list) { | ||
| if (!Array.isArray(list)) { | ||
| throw new Error("calculateMean requires an array of numbers"); | ||
| } | ||
|
|
||
| if (list.length === 0) { | ||
| throw new Error("calculateMean requires a non-empty array"); | ||
| } | ||
|
|
||
| if ( | ||
| !list.every( | ||
| (value) => | ||
| typeof value === "number" && | ||
| !Number.isNaN(value) && | ||
| Number.isFinite(value) | ||
| ) | ||
|
cjyuan marked this conversation as resolved.
Resolved
|
||
| ) { | ||
| throw new Error("calculateMean requires an array of numbers"); | ||
| } | ||
|
|
||
| const total = sum(list); | ||
| const mean = total / list.length; | ||
|
|
||
| return mean; | ||
| } | ||
|
|
||
| module.exports = calculateMean; | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,24 @@ | ||
| function sum(elements) { | ||
| if (!Array.isArray(elements)) { | ||
| throw new Error("sum requires an array of numbers"); | ||
| } | ||
|
|
||
| if ( | ||
| !elements.every( | ||
| (value) => | ||
| typeof currentValue === "number" && | ||
| !Number.isNaN(value) && | ||
| Number.isFinite(value) | ||
| ) | ||
| ) { | ||
| throw new Error("sum requires an array of numbers"); | ||
| } | ||
|
|
||
| let total = 0; | ||
| for (number of elements) { | ||
| total += number; | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| module.exports = sum; |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Could you find out which of these checks are redundant?