-
-
Notifications
You must be signed in to change notification settings - Fork 283
West Midlands | 26-Jan-ITP | Fida Ali Zada | Sprint 1 | Data Groups #982
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
12 commits
Select commit
Hold shift + click to select a range
d5f3e06
Implemented calculateMedian function
alizada-dev 868c5b9
fixed findMax function
alizada-dev 08758cb
fixed sum function and wrote tests
alizada-dev 0c5f55e
fixed dedupe function and wrote tests
alizada-dev f978ff5
'includes' function refactured
alizada-dev 182d369
stretch exercise done
alizada-dev b612d99
fixed median function issues
alizada-dev 7c10e76
changed the implementation
alizada-dev dacc81f
changed the implementation in max and max.test
alizada-dev b62ff40
changed the implementation in the sum.js and test method in sum.test.js
alizada-dev f51817c
Nodejs File System (fs) issue solved
alizada-dev e9ae929
dedupe test
alizada-dev 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
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,15 @@ | ||
| function dedupe() {} | ||
| function dedupe(array) { | ||
| // let arr = array.filter((item, index) => { | ||
|
|
||
| // // indexOf() returns the first index where that value appears in the array. | ||
| // if (array.indexOf(item) === index) { | ||
| // return item; | ||
| // } | ||
| // }) | ||
|
|
||
| // return arr; | ||
|
|
||
| return [...new Set(array)]; | ||
| } | ||
|
|
||
| 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,11 @@ | ||
| function findMax(elements) { | ||
| const numbers = elements.filter(Number.isFinite); | ||
|
|
||
| if (numbers.length == 0) { | ||
| return -Infinity; | ||
| } | ||
|
|
||
| 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,9 @@ | ||
| function sum(elements) { | ||
|
|
||
| // const filteredArr = elements.filter(x => typeof x === 'number'); | ||
| // return filteredArr.reduce((a, b) => a + b, 0); | ||
|
|
||
| return elements.filter(Number.isFinite).reduce((a, b) => a + b, 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
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
|
cjyuan marked this conversation as resolved.
|
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,12 @@ | ||
| const fs = require('fs'); | ||
|
|
||
| const data = fs.readFileSync('input.txt', 'utf-8'); | ||
|
|
||
| // split by spaces or new lines | ||
| // filter out empty values | ||
| // convert strings into numbers | ||
| const numbers = data.split(/\s+/).filter(Boolean).map(Number); | ||
|
|
||
| const sum = numbers.reduce((a, b) => a + b, 0); | ||
|
|
||
| console.log(sum); // 529 |
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.
This test should fail if the function returns the original array (instead of a copy of the original array).
The current test checks only if both the original array and the returned array contain identical elements.
In order to validate the returned array is a different array, we need an additional check.
Can you find out what this additional check is?
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.
By implementing
return [...new Set(array)];, the test will pass correctly, because this implementation always returns a new array.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.
The concern here is not about your function implementation -- it was correct.
The issue is, how to prepare a test to check if the function is indeed returning a copy of the original array.
With the test you had, a function like this could also pass the test.
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.
const input = [1, 3, 5, 7];const result = dedupe(input);expect(result).toEqual(input);expect(result).not.toBe(input);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.
With this test, there is a chance that, even though
resulthas incorrect elements (for example,[]),the two tests could still pass. Can you figure out why, and then fix the tests accordingly?
Uh oh!
There was an error while loading. Please reload this page.
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.
Is it alright, this time?
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.
Still not correct. Try looking up the difference between
toBe()andtoEqual().