generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 270
Birmingham | 26 JAN ITP | Merve Reis | Sprint 1 | Data Groups #1021
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
mervereis
wants to merge
8
commits into
CodeYourFuture:main
Choose a base branch
from
mervereis: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
8 commits
Select commit
Hold shift + click to select a range
c49c63c
median function updated according to requests
mervereis 8bac04f
dedupe function created & test cases created
mervereis 64e7ec0
findMax function created & test cases created
mervereis 4fb2396
sum function created & test cases created
mervereis 1c7be9a
includes function updated
mervereis 989bcb6
NaN and Infinite changes applied to function and test cases added
mervereis 411b770
numeric string coverage applied to function and test cases
mervereis e18f19c
sum function updated and float coverage added to test cases
mervereis 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,6 @@ | ||
| function dedupe() {} | ||
| function dedupe(arr) { | ||
| if (arr.length === 0) return []; | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,50 @@ | ||
| const dedupe = require("./dedupe.js"); | ||
| /* | ||
| Dedupe Array | ||
| const dedupe = require("./dedupe"); | ||
|
|
||
| 📖 Dedupe means **deduplicate** | ||
| describe("dedupe", () => { | ||
| // Given an empty array | ||
| // When passed to the dedupe function | ||
| // Then it should return an empty array | ||
| test.todo("given an empty array, it returns an empty array"); | ||
| test("given an empty array, it returns an empty array", () => { | ||
| const result = dedupe([]); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| In this kata, you will need to deduplicate the elements of an array | ||
| // Given an array with no duplicates | ||
| // When passed to the dedupe function | ||
| // Then it should return a copy of the original array | ||
| test("given an array with no duplicates, it returns a copy of the original array", () => { | ||
| const input = [1, 2, 3, 4]; | ||
| const result = dedupe(input); | ||
|
|
||
| E.g. dedupe(['a','a','a','b','b','c']) target output: ['a','b','c'] | ||
| E.g. dedupe([5, 1, 1, 2, 3, 2, 5, 8]) target output: [5, 1, 2, 3, 8] | ||
| E.g. dedupe([1, 2, 1]) target output: [1, 2] | ||
| */ | ||
| expect(result).toEqual([1, 2, 3, 4]); | ||
| expect(result).not.toBe(input); // should be a new copy | ||
| }); | ||
|
|
||
| // Acceptance Criteria: | ||
| // Given an array with strings | ||
| // When passed to the dedupe function | ||
| // Then it should remove duplicates preserving first occurrence | ||
| test("removes duplicate strings preserving first occurrence", () => { | ||
| const input = ["a", "a", "a", "b", "b", "c"]; | ||
| const result = dedupe(input); | ||
|
|
||
| // Given an empty array | ||
| // When passed to the dedupe function | ||
| // Then it should return an empty array | ||
| test.todo("given an empty array, it returns an empty array"); | ||
| expect(result).toEqual(["a", "b", "c"]); | ||
| }); | ||
|
|
||
| // Given an array with no duplicates | ||
| // When passed to the dedupe function | ||
| // Then it should return a copy of the original array | ||
| // Given an array with numbers | ||
| // When passed to the dedupe function | ||
| // Then it should remove the duplicate values, preserving the first occurence of each element | ||
| test("removes duplicate numbers preserving first occurrence", () => { | ||
| const input = [5, 1, 1, 2, 3, 2, 5, 8]; | ||
| const result = dedupe(input); | ||
|
|
||
| // Given an array with strings or numbers | ||
| // When passed to the dedupe function | ||
| // Then it should remove the duplicate values, preserving the first occurence of each element | ||
| expect(result).toEqual([5, 1, 2, 3, 8]); | ||
| }); | ||
|
|
||
| test("removes duplicates in mixed order", () => { | ||
| const input = [1, 2, 1]; | ||
| const result = dedupe(input); | ||
|
|
||
| expect(result).toEqual([1, 2]); | ||
| }); | ||
| }); |
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,23 @@ | ||
| function findMax(elements) { | ||
| if (!Array.isArray(elements)) { | ||
| return -Infinity; | ||
| } | ||
|
|
||
| const numbers = elements.filter((el) => Number.isFinite(el)); | ||
|
|
||
| if (numbers.length === 0) { | ||
| return -Infinity; | ||
| } | ||
|
|
||
| let max = numbers[0]; | ||
|
|
||
| for (let i = 1; i < numbers.length; i++) { | ||
| if (numbers[i] > max) { | ||
| max = numbers[i]; | ||
| } | ||
| } | ||
|
|
||
| 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,68 @@ | ||
| /* Find the maximum 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. | ||
| const findMax = require("./max.js"); | ||
|
|
||
| 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) | ||
| describe("findMax", () => { | ||
| // Given an empty array | ||
| // When passed to the max function | ||
| // Then it should return -Infinity | ||
| test("given an empty array, returns -Infinity", () => { | ||
| expect(findMax([])).toBe(-Infinity); | ||
| }); | ||
|
|
||
| You should implement this function in max.js, and add tests for it in this file. | ||
| // Given an array with one number | ||
| // When passed to the max function | ||
| // Then it should return that number | ||
| test("given an array with one number, returns that number", () => { | ||
| expect(findMax([5])).toBe(5); | ||
| }); | ||
|
|
||
| We have set things up already so that this file can see your function from the other file. | ||
| */ | ||
| // Given an array with both positive and negative numbers | ||
| // When passed to the max function | ||
| // Then it should return the largest number overall | ||
| test("returns the largest number from positive and negative numbers", () => { | ||
| expect(findMax([-10, 20, -5, 15])).toBe(20); | ||
| }); | ||
|
|
||
| const findMax = require("./max.js"); | ||
| // Given an array with just negative numbers | ||
| // When passed to the max function | ||
| // Then it should return the closest one to zero | ||
| test("returns the largest number among negative numbers", () => { | ||
| expect(findMax([-10, -3, -50, -1])).toBe(-1); | ||
| }); | ||
|
|
||
| // Given an empty array | ||
| // When passed to the max function | ||
| // Then it should return -Infinity | ||
| // Delete this test.todo and replace it with a test. | ||
| test.todo("given an empty array, returns -Infinity"); | ||
| // Given an array with decimal numbers | ||
| // When passed to the max function | ||
| // Then it should return the largest decimal number | ||
| test("returns the largest decimal number", () => { | ||
| expect(findMax([1.2, 3.7, 2.5, 3.6])).toBe(3.7); | ||
| }); | ||
|
|
||
| // Given an array with one number | ||
| // When passed to the max function | ||
| // Then it should return that number | ||
| // Given an array with non-number values | ||
| // When passed to the max function | ||
| // Then it should return the max and ignore non-numeric values | ||
| test("ignores non-number values (including numeric strings)", () => { | ||
| expect(findMax(["hey", 10, "300", 60, 10])).toBe(60); | ||
| }); | ||
|
|
||
| // Given an array with both positive and negative numbers | ||
| // When passed to the max function | ||
| // Then it should return the largest number overall | ||
| // Given an array with only non-number values | ||
| // When passed to the max function | ||
| // Then it should return the least surprising value given how it behaves for all other inputs | ||
| test("returns -Infinity when array has only non-number values", () => { | ||
| expect(findMax(["a", "b", "c"])).toBe(-Infinity); | ||
| }); | ||
|
|
||
| // Given an array with just negative numbers | ||
| // When passed to the max function | ||
| // Then it should return the closest one to zero | ||
| test("does not treat numeric strings as numbers", () => { | ||
| expect(findMax([20, "300"])).toBe(20); | ||
| }); | ||
|
|
||
| // Given an array with decimal numbers | ||
| // When passed to the max function | ||
| // Then it should return the largest decimal number | ||
| test("returns -Infinity when only numeric strings are present", () => { | ||
| expect(findMax(["100", "200", "300"])).toBe(-Infinity); | ||
| }); | ||
|
|
||
| // Given an array with non-number values | ||
| // When passed to the max function | ||
| // Then it should return the max and ignore non-numeric values | ||
| test("ignores NaN and Infinity values", () => { | ||
| expect(findMax([10, NaN, 50, Infinity, -Infinity])).toBe(50); | ||
| }); | ||
|
|
||
| // Given an array with only non-number values | ||
| // When passed to the max function | ||
| // Then it should return the least surprising value given how it behaves for all other inputs | ||
| test("returns -Infinity when only NaN and Infinity are present", () => { | ||
| expect(findMax([NaN, Infinity, -Infinity])).toBe(-Infinity); | ||
| }); | ||
| }); |
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) { | ||
| const numbers = elements.filter((el) => Number.isFinite(el)); | ||
| const sumNumbers = numbers.reduce((a, b) => a + b, 0); | ||
| return sumNumbers; | ||
| } | ||
|
|
||
| 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.
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.
Why do you need this "extra safety" to make a copy of numbers before sorting? Safety from what?