-
-
Notifications
You must be signed in to change notification settings - Fork 327
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
18
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
18 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 0aa3281
median.js throw error
mandipsanger c8b1605
incoming changes
mandipsanger 6f43ab5
acceipt new changes
mandipsanger 19b40af
accepted incoming changes
mandipsanger 4359456
accepted incoming changes for sum.js and sum.test.js
mandipsanger 36695b5
Merge branch 'main' into sprint-1
mandipsanger abc979e
sorting median.js
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
| 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) { | ||
| function findMax(list) { | ||
| if (!Array.isArray(list)) { | ||
| throw new Error("findMax requires an array of numbers"); | ||
| } | ||
|
|
||
| if (!list.every((item) => typeof item === "number" && !Number.isNaN(item))) { | ||
| throw new Error("findMax requires an array of numbers"); | ||
| } | ||
|
|
||
| return Math.max(...list); | ||
| } | ||
|
|
||
| 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,89 @@ | ||
| /* 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]) throws Error("findMax requires an array of numbers") (max can't compare non-numerical elements, so it shouldn't guess) | ||
| 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 the number when the array contains 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 the 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("returns the number closest to zero", () => { | ||
| 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("returns the largest decimal number", () => { | ||
| const currentOutput = findMax([2.5, 5.6]); | ||
| const targetOutput = 5.6; | ||
|
|
||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an array containing a value that isn't a number | ||
| // When passed to the max function | ||
| // When passed to the findMax function | ||
| // Then it should throw Error("findMax requires an array of numbers") | ||
| test("throws an error when the array contains a non-number", () => { | ||
| expect(() => findMax(["hey", 10, "hi", 60, 10])).toThrow( | ||
| new Error("findMax requires an array of numbers") | ||
| ); | ||
| }); | ||
|
|
||
| // Given something that isn't an array at all, such as "hey", 42 or no argument | ||
| // When passed to the max function | ||
| // Given something that isn't an array at all | ||
| // When passed to the findMax function | ||
| // Then it should throw Error("findMax requires an array of numbers") | ||
| test("throws an error when the input is not an array", () => { | ||
| expect(() => findMax("hey")).toThrow( | ||
| new Error("findMax requires an array of numbers") | ||
| ); | ||
|
|
||
| expect(() => findMax(42)).toThrow( | ||
| new Error("findMax requires an array of numbers") | ||
| ); | ||
|
|
||
| expect(() => findMax()).toThrow( | ||
| new Error("findMax requires an array of numbers") | ||
| ); | ||
| }); |
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) { | ||
| function sum(list) { | ||
| if (!Array.isArray(list)) { | ||
| throw new Error("sum requires an array of numbers"); | ||
| } | ||
|
|
||
| if (!list.every((item) => typeof item === "number" && !Number.isNaN(item))) { | ||
| throw new Error("sum requires an array of numbers"); | ||
| } | ||
|
|
||
| return list.reduce((total, number) => total + number, 0); | ||
| } | ||
|
|
||
| module.exports = sum; |
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.