generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 221
London | 25-ITP-Sep| Sophia Mohamed | Sprint 1 | Sprint 1 Coursework #854
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
19 commits
Select commit
Hold shift + click to select a range
88fcfd6
fixed the implementation
saff-coder ff94433
fixed median.js
saff-coder 4aaa10e
Install and edit package.json
saff-coder b0f2edf
updated the code
saff-coder d9cdfcb
run all the tests
saff-coder d65bf50
implement the find max code
saff-coder da633c5
modified the test
saff-coder 97787fd
edit the test
saff-coder 381088b
fix calculateMedian
saff-coder d2f9b7d
Merge branch 'Sprint-1' of https://github.com/saff-coder/Module-Data-…
saff-coder eb61923
updated package.json file
saff-coder 08b8868
fix package
saff-coder ec8d9b5
fix package file
saff-coder 4cebc73
editing
saff-coder 53cd18a
all the implementation is done
saff-coder 6622e22
updated all thr functions run the test required
saff-coder b7c0519
updated the codes
saff-coder e6b819e
updated all the tests and functions
saff-coder 1096a41
Done all the updates needed
saff-coder 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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "cyf-sprint-1", | ||
| "version": "1.0.0", | ||
| "description": "Sprint 1 solutions", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "jest" | ||
| }, | ||
| "devDependencies": { | ||
| "jest": "^29.0.0" | ||
| }, | ||
| "author": "", | ||
| "license": "MIT" | ||
| } |
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,16 @@ | ||
| function dedupe() {} | ||
| function dedupe(arr) { | ||
| const result = []; // This empty array will store unique items | ||
| const seen = new Set(); // Used to track what we've already seen | ||
|
|
||
| for (let item of arr) { | ||
| if (!seen.has(item)) { | ||
| seen.add(item); | ||
| result.push(item); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| 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,37 @@ | ||
| const dedupe = require("./dedupe.js"); | ||
|
|
||
| /* | ||
| Dedupe Array | ||
| Dedupe = remove duplicates while keeping the first occurrence | ||
| */ | ||
|
|
||
| 📖 Dedupe means **deduplicate** | ||
| // TEST 1 — empty array | ||
| test("given an empty array, it returns an empty array", () => { | ||
| expect(dedupe([])).toEqual([]); | ||
| }); | ||
|
|
||
| In this kata, you will need to deduplicate the elements of an array | ||
| // TEST 2 — no duplicates (should return a copy) | ||
| test("given an array with no duplicates, it returns a copy of the array", () => { | ||
| const arr = [1, 2, 3, 4]; | ||
| const result = dedupe(arr); | ||
|
|
||
| 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(arr); // important check | ||
| }); | ||
|
|
||
| // Acceptance Criteria: | ||
| // TEST 3 — removes duplicates | ||
| test("given an array with duplicates, it removes duplicates and preserves first occurrence", () => { | ||
| expect(dedupe(['a', 'a', 'b', 'c', 'c'])).toEqual(['a', 'b', 'c']); | ||
| expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]); | ||
| expect(dedupe([1, 2, 1])).toEqual([1, 2]); | ||
| }); | ||
|
|
||
| // 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 4 — should not mutate original array | ||
| test("does not mutate the original array", () => { | ||
| const arr = [1, 1, 2, 3]; | ||
| const copy = [...arr]; | ||
|
|
||
| // Given an array with no duplicates | ||
| // When passed to the dedupe function | ||
| // Then it should return a copy of the original array | ||
| dedupe(arr); | ||
|
|
||
| // 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(arr).toEqual(copy); // original unchanged | ||
| }); | ||
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,24 @@ | ||
| function findMax(elements) { | ||
| // If it's not an array, we can't process it | ||
| if (!Array.isArray(elements)) { | ||
| return null; | ||
| } | ||
|
|
||
| // Given an empty array, return -Infinity | ||
| if (elements.length === 0) { | ||
| return -Infinity; | ||
| } | ||
|
|
||
| // Keep only numeric values | ||
| const numericValues = elements.filter((el) => typeof el === "number"); | ||
|
|
||
| // If there are no numeric values at all, return null | ||
| if (numericValues.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| // Return the largest number (works for positive, negative, decimals) | ||
| return Math.max(...numericValues); | ||
| } | ||
|
|
||
| module.exports = findMax; | ||
| 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,19 @@ | ||
| function sum(elements) { | ||
|
|
||
| function sum(arr) { | ||
| // If not an array, return 0 safely | ||
| if (!Array.isArray(arr)) return 0; | ||
|
|
||
| let total = 0; | ||
|
|
||
| for (let item of arr) { | ||
| if (typeof item === "number" && !isNaN(item)) { | ||
| total += item; | ||
| } | ||
| } | ||
|
|
||
| return total; | ||
| } | ||
|
|
||
| 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
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.
Nicely done.