-
-
Notifications
You must be signed in to change notification settings - Fork 326
London | 26-ITP-May | Mandip Sanger| Sprint 1| Data groups #1392
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
mandipsanger
wants to merge
11
commits into
CodeYourFuture:main
Choose a base branch
from
mandipsanger: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
11 commits
Select commit
Hold shift + click to select a range
120dd16
dedupe errors fix
mandipsanger eb7a06e
median
mandipsanger 1792362
dedupe
mandipsanger b9f2392
fix errors
mandipsanger 3ecea9e
max test
mandipsanger b27a4d8
fix failing tests
mandipsanger 01d1831
implemented max
mandipsanger 49dd8e3
replace original
mandipsanger fe018ee
removing the test cases
mandipsanger 9cd6eab
dedupe implement fix
mandipsanger 2bb6031
replacing invert file
mandipsanger 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
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,13 @@ | ||
| function findMax(elements) { | ||
| const numbersOnly = elements.filter( | ||
| (item) => typeof item === "number" && !Number.isNaN(item) | ||
| ); | ||
| if (numbersOnly.length === 0) { | ||
| return -Infinity; | ||
| } | ||
| const sorted = [...numbersOnly].sort((a, b) => a - b); | ||
| const max = sorted[sorted.length - 1]; | ||
|
mandipsanger marked this conversation as resolved.
|
||
| return max; | ||
| } | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,81 @@ | ||
| /* Find the maximum element of an array of numbers | ||
| /* Find the findMaximum element of an array of numbers | ||
|
|
||
| In this kata, you will need to implement a function that find the largest numerical element of an array. | ||
|
|
||
| E.g. max([30, 50, 10, 40]), target output: 50 | ||
| E.g. max(['hey', 10, 'hi', 60, 10]), target output: 60 (sum ignores any non-numerical elements) | ||
| E.g. findMax([30, 50, 10, 40]), target output: 50 | ||
| E.g. findMax(['hey', 10, 'hi', 60, 10]), target output: 60 (sum ignores any non-numerical elements) | ||
|
|
||
| You should implement this function in max.js, and add tests for it in this file. | ||
| You should implement this function in findMax.js, and add tests for it in this file. | ||
|
|
||
| We have set things up already so that this file can see your function from the other file. | ||
| */ | ||
|
|
||
| const findMax = require("./max.js"); | ||
|
|
||
| // Given an empty array | ||
| // When passed to the max function | ||
| // When passed to the findMax function | ||
| // Then it should return -Infinity | ||
| // Delete this test.todo and replace it with a test. | ||
| test.todo("given an empty array, returns -Infinity"); | ||
|
|
||
| test("returns -Infinity for an empty array", () => { | ||
| const currentOutput = findMax([]); | ||
| const targetOutput = -Infinity; | ||
|
|
||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an array with one number | ||
| // When passed to the max function | ||
| // When passed to the findMax function | ||
| // Then it should return that number | ||
|
|
||
| test("returns with one number", () => { | ||
| const currentOutput = findMax([3]); | ||
| const targetOutput = 3; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an array with both positive and negative numbers | ||
| // When passed to the max function | ||
| // When passed to the findMax function | ||
| // Then it should return the largest number overall | ||
| test("returns largest number", () => { | ||
| const currentOutput = findMax([3, -10]); | ||
| const targetOutput = 3; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an array with just negative numbers | ||
| // When passed to the max function | ||
| // When passed to the findMax function | ||
| // Then it should return the closest one to zero | ||
| test("return closest to 0", () => { | ||
| const currentOutput = findMax([-7, -3, -10]); | ||
| const targetOutput = -3; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an array with decimal numbers | ||
| // When passed to the max function | ||
| // When passed to the findMax function | ||
| // Then it should return the largest decimal number | ||
| test("return to largest decimal number", () => { | ||
| const currentOutput = findMax([2.5, 5.6]); | ||
| const targetOutput = 5.6; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an array with non-number values | ||
| // When passed to the max function | ||
| // Then it should return the max and ignore non-numeric values | ||
| // When passed to the findMax function | ||
| // Then it should return the findMax and ignore non-numeric values | ||
|
|
||
| test("return to findMax and ignore non-numeric values", () => { | ||
| const currentOutput = findMax([7, 4, -10, "b", "f"]); | ||
| const targetOutput = 7; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an array with only non-number values | ||
| // When passed to the max function | ||
| // When passed to the findMax function | ||
| // Then it should return the least surprising value given how it behaves for all other inputs | ||
| test("return the least surprising value", () => { | ||
| const currentOutput = findMax([NaN, "hi", true]); | ||
| const targetOutput = -Infinity; | ||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); |
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,13 @@ | ||
| function sum(elements) { | ||
| let total = 0; | ||
|
|
||
| for (let i = 0; i < elements.length; i++) { | ||
| if (typeof elements[i] === "number" && !isNaN(elements[i])) { | ||
| total += elements[i]; | ||
| } | ||
| } | ||
|
|
||
| return total; | ||
| } | ||
|
|
||
| module.exports = sum; |
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.
Uh oh!
There was an error while loading. Please reload this page.