Repository navigation
Manchester |26-ITP-Sep | Precious Moses | Sprint 1 | Data Groups #1479
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
moses77-boop
wants to merge
60
commits into
CodeYourFuture:main
Choose a base branch
from
moses77-boop: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.
+999
−730
Open
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
09fe065
Fix median calculation to return correct value from the list
moses77-boop 1fde0e0
Fix median calculation to handle both odd and even length lists
moses77-boop ecfa4aa
Fix median calculation to use sorted list
moses77-boop fd8ec66
Add error handling for input validation to calculateMedian function
moses77-boop e3e6ea5
Add error handling for empty array
moses77-boop e95631c
Add error handling to ensure all elements in the array are numbers
moses77-boop bba68b6
Implement test for empty array case in findMax function
moses77-boop 66a3e6a
Add input validation to findMax function to ensure an array is provided
moses77-boop ed01080
Refactor findMax function to include max initialization
moses77-boop b564d44
Add test for single number array case in findMax function
moses77-boop f104afb
Refactor findMax function
moses77-boop b6f529d
Add test for non-number input in findMax function
moses77-boop c7b0e6e
Add test for non-array inputs in findMax function
moses77-boop 872a29b
Add test for finding the maximum number in an array with positive and…
moses77-boop 6db3742
Add test for finding the closest number to zero in an array of negati…
moses77-boop 82f5c3a
Add test for finding the largest decimal number in an array
moses77-boop 7aaff3c
Add test for handling non-number elements in sum function
moses77-boop 02c2e87
Add error handling for non-array inputs in sum function
moses77-boop 44bf4cf
Implement test for returning 0 when given an empty array in sum function
moses77-boop 0a3d100
Refactor sum function to improve error handling and ensure input is a…
moses77-boop 5506d62
Add test for handling non-array inputs in sum function
moses77-boop 1507d42
Add test for handling single number input in sum function
moses77-boop cc8664c
Add test for handling negative numbers in sum function
moses77-boop c229437
Add test for handling decimal numbers in sum function
moses77-boop 6b578bf
Fix test for decimal numbers in sum function to use toBeCloseTo for p…
moses77-boop 4b21f36
Fix test for decimal numbers in sum function to return correct total
moses77-boop 6fc8984
Implement export command for dedupe function
moses77-boop fb39a6b
Implement test for dedupe function to handle empty array case
moses77-boop 4ee500d
Implement dedupe function
moses77-boop 6d78cdb
Implement test for dedupe function to handle arrays with no duplicates
moses77-boop 7130597
Refactor dedupe function to accept an array parameter and iterate thr…
moses77-boop b3bd915
Add test for dedupe function to handle arrays with duplicate strings
moses77-boop aafec32
Refactor dedupe function to prevent adding duplicates to the uniqueIt…
moses77-boop 70f312c
Add test for dedupe function to handle arrays of numbers with duplicates
moses77-boop 6f4c2d4
Implement test for calculateMean function to verify mean calculation …
moses77-boop f96c928
Implement calculateMean function to compute the average of an array o…
moses77-boop 9b1afc7
Add tests for calculateMean function to handle single numbers, negati…
moses77-boop 84122b3
Add test for calculateMean function to verify error handling for empt…
moses77-boop 7eeab41
Add error handling to calculateMean function for empty arrays
moses77-boop bece9ad
Add tests for calculateMean function to handle non-array inputs
moses77-boop c0a278a
Add input validation to calculateMean function for non-array inputs
moses77-boop 0bb1418
Add test for calculateMean function to handle no arguments
moses77-boop 55521a9
Add test for calculateMean function to handle non-number values in array
moses77-boop cd600e2
Add input validation for array elements in calculateMean function
moses77-boop 0ab70f6
Implement test for describeMedian function to validate median calcula…
moses77-boop 3cd3611
Implement describeMedian function to return median value as a string
moses77-boop 783326c
Add tests for empty array cases
moses77-boop b9f0e90
Add error handling to describeMedian function for invalid input
moses77-boop 74b3e77
Fix test typo in error message for empty array case
moses77-boop c08e109
Add test for non-number value of array case in describeMedian and fix…
moses77-boop 435bc33
Fix typo in error message for median calculation failure
moses77-boop 068ad9d
Refactor includes function to use for...of loop for improved readability
moses77-boop 3f5b5d3
Update input data for aoc-2018-day1 with new values and formatting ad…
moses77-boop d1b8c93
Implement frequency calculation logic and handle duplicate frequencies
moses77-boop de542e0
Refactor loop structure for improved readability in frequency calcula…
moses77-boop 2061fba
Refactor mean test cases for improved readability and consistency
moses77-boop 0afbaed
Refactor error handling tests for non-array inputs in calculateMean f…
moses77-boop ca719e8
Refactor formatting for consistency in calculateMean function
moses77-boop 5d3b691
Refactor sum function for improved formatting and consistency
moses77-boop 9710b41
Refactor sum test cases for improved readability and consistency
moses77-boop 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,16 @@ | ||
| function dedupe() {} | ||
| function dedupe(originalArray) { | ||
| const uniqueItems = []; | ||
|
|
||
| for (let i = 0; i < originalArray.length; i++) { | ||
| const currentItem = originalArray[i]; | ||
| const alreadyInArray = uniqueItems.includes(currentItem); | ||
|
|
||
| if (alreadyInArray === false) { | ||
| uniqueItems.push(currentItem); | ||
| } | ||
| } | ||
|
|
||
| return uniqueItems; | ||
| } | ||
|
|
||
| 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
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,20 @@ | ||
| function findMax(elements) { | ||
| if(!Array.isArray(elements)) { | ||
| throw new Error("findMax requires an array of numbers"); | ||
| } | ||
|
|
||
| let max = -Infinity; | ||
|
|
||
| for (const element of elements) { | ||
| if (typeof element !== "number" || Number.isNaN(element)) { | ||
| throw new Error("findMax requires an array of numbers"); | ||
| } | ||
|
|
||
| if (element > max) { | ||
| max = element; | ||
| } | ||
| } | ||
| 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
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,3 +1,22 @@ | ||
| function calculateMean(list) {} | ||
| function calculateMean(list) { | ||
| if (!Array.isArray(list)) { | ||
| throw new Error("calculateMean requires an array of numbers"); | ||
| } | ||
|
|
||
| if (list.length === 0) { | ||
| throw new Error("calculateMean requires a non-empty array"); | ||
| } | ||
|
|
||
| let total = 0; | ||
|
|
||
| for (let i = 0; i < list.length; i++) { | ||
| if (typeof list[i] !== "number") { | ||
| throw new Error("calculateMean requires an array of numbers"); | ||
| } | ||
| total += list[i]; | ||
| } | ||
|
|
||
| return total / list.length; | ||
| } | ||
|
|
||
| module.exports = calculateMean; | ||
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 |
|---|---|---|
|
|
@@ -22,29 +22,70 @@ const calculateMean = require("./mean.js"); | |
| // Given an array of numbers | ||
| // When passed to calculateMean | ||
| // Then it should return their mean | ||
| // Delete this test.todo and replace it with a test. | ||
| test.todo("given [1, 2, 6], returns 3"); | ||
| test("given [1, 2, 6], returns 3", () => { | ||
| expect(calculateMean([1, 2, 6])).toBe(3); | ||
| }); | ||
|
|
||
| // Given an array with a single number | ||
| // When passed to calculateMean | ||
| // Then it should return that number | ||
| test("given [7], return 7", () => { | ||
| expect(calculateMean([7])).toBe(7); | ||
| }); | ||
|
|
||
| // Given an array containing negative or decimal numbers | ||
| // When passed to calculateMean | ||
| // Then it should return the correct mean | ||
| test("given an array of negative numbers, return the correct mean", () => { | ||
| expect(calculateMean([-1, -3, -5])).toBe(-3); | ||
| }); | ||
|
|
||
| test("given an array of decimal numbers, return the correct mean", () => { | ||
| expect(calculateMean([1.5, 2.5])).toBe(2); | ||
| expect(calculateMean([0.1, 0.2])).toBeCloseTo(0.15); | ||
| }); | ||
|
|
||
| // Given an empty array | ||
| // When passed to calculateMean | ||
| // Then it should throw Error("calculateMean requires a non-empty array") | ||
| test("given an empty array, throws an error", () => { | ||
| expect(() => calculateMean([])).toThrow( | ||
| "calculateMean requires a non-empty array" | ||
| ); | ||
| }); | ||
|
|
||
| // Given a value that isn't an array, e.g. "banana", 42, null or {} | ||
| // When passed to calculateMean | ||
| // Then it should throw Error("calculateMean requires an array of numbers") | ||
| test("given a value that is not an array, throws an error", () => { | ||
| expect(() => calculateMean("banana")).toThrow( | ||
| "calculateMean requires an array of numbers" | ||
| ); | ||
| expect(() => calculateMean(42)).toThrow( | ||
| "calculateMean requires an array of numbers" | ||
| ); | ||
| expect(() => calculateMean(null)).toThrow( | ||
| "calculateMean requires an array of numbers" | ||
| ); | ||
| expect(() => calculateMean({})).toThrow( | ||
| "calculateMean requires an array of numbers" | ||
| ); | ||
| }); | ||
|
Comment on lines
+60
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could consider grouping these test cases into one category; they have the same test description.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code refactored. |
||
|
|
||
| // Given no argument at all | ||
| // When passed to calculateMean | ||
| // Then it should throw Error("calculateMean requires an array of numbers") | ||
| test("given no argument at all, throws an error", () => { | ||
| expect(() => calculateMean()).toThrow( | ||
| "calculateMean requires an array of numbers" | ||
| ); | ||
| }); | ||
|
|
||
| // Given an array containing a non-number value, e.g. [1, "2", 3] | ||
| // When passed to calculateMean | ||
| // Then it should throw Error("calculateMean requires an array of numbers") | ||
| test("given an array with a non-number, throws an error", () => { | ||
| expect(() => calculateMean([7, "2", 5])).toThrow( | ||
| "calculateMean 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,18 @@ | ||
| function sum(elements) { | ||
| if (!Array.isArray(elements)) { | ||
| throw new Error("sum requires an array of numbers"); | ||
| } | ||
|
|
||
| let total = 0; | ||
|
|
||
| for (const element of elements) { | ||
| if (!Number.isFinite(element)) { | ||
| throw new Error("sum requires an array of numbers"); | ||
| } | ||
| total += element; | ||
| } | ||
|
|
||
| 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
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.
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.
Spacing a bit inconsistent after
if.