-
-
Notifications
You must be signed in to change notification settings - Fork 320
London | 26-ITP-Jan | Miriam Jorna | Sprint 1 | Data Groups #1126
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5f73bcd
Homework for Sprint-1
miriamjorna 5fe58dc
Sorting out CJ's comments on version 1
miriamjorna 211a6f7
Existential answer to dedupe is .not.toBe
miriamjorna bd958d5
Last changes to comply with reviewer's remarks
miriamjorna c668ec9
The refactor exercise
miriamjorna 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,37 @@ | ||
|
|
||
| // Fix this implementation | ||
| // Start by running the tests for this function | ||
| // If you're in the Sprint-1 directory, you can run `npm test -- fix` to run the tests in the fix directory | ||
| // If you're in the Sprint-1 directory, you can run `npm test -- fix` | ||
| // to run the tests in the fix directory | ||
|
|
||
| // Hint: Please consider scenarios when 'list' doesn't have numbers (the function is expected to return null) | ||
| // or 'list' has mixed values (the function is expected to sort only numbers). | ||
|
|
||
| function calculateMedian(list) { | ||
| const middleIndex = Math.floor(list.length / 2); | ||
| const median = list.splice(middleIndex, 1)[0]; | ||
| return median; | ||
| // return null if input is not an array | ||
| if (!Array.isArray(list)) { | ||
| return null; | ||
| } | ||
|
|
||
| // filter only numbers from the list | ||
| const numbers = list.filter(item => Number.isFinite(item)); | ||
|
|
||
| // return null if no numbers found | ||
| if (numbers.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| // sort the numbers | ||
| numbers.sort((a, b) => a - b); | ||
|
|
||
| const middleIndex = Math.floor(numbers.length / 2); | ||
|
|
||
| // if even number of elements, average the two middle values | ||
| if (numbers.length % 2 === 0) { | ||
| return (numbers[middleIndex - 1] + numbers[middleIndex]) / 2; | ||
| } | ||
|
|
||
| return numbers[middleIndex]; | ||
| } | ||
|
|
||
| module.exports = calculateMedian; |
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,5 @@ | ||
| function dedupe() {} | ||
| function dedupe(arr) { | ||
| return [...new Set(arr)]; | ||
| } | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| function findMax(elements) { | ||
| function findMax(arr) { | ||
| // filter only numbers from the array | ||
| const numbers = arr.filter(item => Number.isFinite(item)); | ||
| return Math.max(...numbers); | ||
| } | ||
|
|
||
| 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,4 +1,7 @@ | ||
| function sum(elements) { | ||
| function sum(arr) { | ||
| return arr | ||
| .filter(item => Number.isFinite(item)) | ||
| .reduce((total, num) => total + num, 0); | ||
| } | ||
|
|
||
| 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
Empty file.
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| test("calculates the mean of a list of numbers", () => { | ||
| const list = [3, 50, 7]; | ||
| const currentOutput = calculateMean(list); | ||
| const targetOutput = 20; | ||
|
|
||
| expect(currentOutput).toEqual(targetOutput); | ||
|
|
||
| }); |
Empty file.
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| test("calculates the the median of a list of odd length", () => { | ||
| const list = [10, 20, 30, 50, 60]; | ||
| const currentOutput = calculateMedian(list); | ||
| const targetOutput = 30; | ||
|
|
||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| function calculateMedian(list) { | ||
| const middleIndex = Math.floor(list.length / 2); | ||
| const median = list.splice(middleIndex, 1)[0]; | ||
|
|
||
| return median; | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| function calculateMedian(list) { | ||
| const middleIndex = Math.floor(list.length / 2); | ||
| const median = list.splice(middleIndex, 1)[0]; | ||
|
|
||
| return median; | ||
| } | ||
|
|
||
| function calculateMean(list) { | ||
| const sum = list.reduce((acc, val) => acc + val, 0); | ||
| const mean = sum / list.length; | ||
|
|
||
| return mean; | ||
| } | ||
|
|
||
| const salaries = [10, 20, 30, 40, 60, 80, 80]; | ||
| const median = calculateMedian(salaries); | ||
|
|
||
| console.log(salaries, "<--- salaries input before we call calculateMean"); | ||
| const mean = calculateMean(salaries); | ||
|
|
||
| console.log(`The median salary is ${median}`); | ||
| console.log(`The mean salary is ${mean}`); |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.