From 26b44e9fbb34c71feb9839fb532ff9443af8d0bb Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 00:02:21 +0000 Subject: [PATCH 01/51] added a code to fix a test fail,two test passed for even number input array --- Sprint-1/fix/median.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 5c5b796e1..eccfa29a2 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -7,8 +7,13 @@ function calculateMedian(list) { const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; - return median; + if (list.length % 2 === 0) { + median = (list[middleIndex] + list[middleIndex - 1]) / 2; + return median; + } else { + const median = list.splice(middleIndex, 1)[0]; + return median; + } } module.exports = calculateMedian; From 671b6c43f4f977d4e56b90c7020cf7211f257ff2 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 00:13:38 +0000 Subject: [PATCH 02/51] added a code for a test that failed when unsorted array, 4 tests passed --- Sprint-1/fix/median.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index eccfa29a2..937f07cc3 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -7,11 +7,12 @@ function calculateMedian(list) { const middleIndex = Math.floor(list.length / 2); + const sortedList = list.sort((a, b) => a - b); if (list.length % 2 === 0) { - median = (list[middleIndex] + list[middleIndex - 1]) / 2; + const median = (sortedList[middleIndex] + sortedList[middleIndex - 1]) / 2; return median; } else { - const median = list.splice(middleIndex, 1)[0]; + const median = sortedList.splice(middleIndex, 1)[0]; return median; } } From 0eedf377156177ce01b480113493257226140953 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 00:23:31 +0000 Subject: [PATCH 03/51] added a code that throws a test when passed empty array,test passed --- Sprint-1/fix/median.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 937f07cc3..1e31f0cb3 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -8,6 +8,9 @@ function calculateMedian(list) { const middleIndex = Math.floor(list.length / 2); const sortedList = list.sort((a, b) => a - b); + if (list.length === 0) { + throw new Error("calculateMedian requires a non-empty array"); + } if (list.length % 2 === 0) { const median = (sortedList[middleIndex] + sortedList[middleIndex - 1]) / 2; return median; From df36aaeb1ac88738b1bfd7d3efcf0624ab69d199 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 00:42:37 +0000 Subject: [PATCH 04/51] added a code that checks if the array has number or other values , four test passed --- Sprint-1/fix/median.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 1e31f0cb3..b6ec5cac2 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -7,10 +7,14 @@ function calculateMedian(list) { const middleIndex = Math.floor(list.length / 2); - const sortedList = list.sort((a, b) => a - b); + if (list.length === 0) { throw new Error("calculateMedian requires a non-empty array"); } + if (!Array.isArray(list)) { + throw new Error("calculateMedian requires an array of numbers"); + } + const sortedList = list.sort((a, b) => a - b); if (list.length % 2 === 0) { const median = (sortedList[middleIndex] + sortedList[middleIndex - 1]) / 2; return median; From b9818ebb0f8239191edc0c0d417629d2e4218e02 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 01:14:10 +0000 Subject: [PATCH 05/51] added codes for the test failling on array of string,mixing numbers, containing null,and undefined. test passed --- Sprint-1/fix/median.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b6ec5cac2..2730996cf 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -14,6 +14,14 @@ function calculateMedian(list) { if (!Array.isArray(list)) { throw new Error("calculateMedian requires an array of numbers"); } + if (!list) { + throw new Error("calculateMedian requires an array of numbers"); + } + for (const item of list) { + if (typeof item !== "number") { + throw new Error("calculateMedian requires an array of numbers"); + } + } const sortedList = list.sort((a, b) => a - b); if (list.length % 2 === 0) { const median = (sortedList[middleIndex] + sortedList[middleIndex - 1]) / 2; From bd50d809e49c92c59cdd24edf95972ac22a5adc8 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 01:29:20 +0000 Subject: [PATCH 06/51] edited codes ,where thier position can catch the error early(the one that checs if list is array or not). test passed --- Sprint-1/fix/median.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 2730996cf..46d09e83c 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,14 +6,13 @@ // or contains values that aren't numbers (the function is expected to throw - see the tests). function calculateMedian(list) { - const middleIndex = Math.floor(list.length / 2); - - if (list.length === 0) { - throw new Error("calculateMedian requires a non-empty array"); - } if (!Array.isArray(list)) { throw new Error("calculateMedian requires an array of numbers"); } + if (list.length === 0) { + throw new Error("calculateMedian requires a non-empty array"); + } + if (!list) { throw new Error("calculateMedian requires an array of numbers"); } @@ -22,13 +21,14 @@ function calculateMedian(list) { throw new Error("calculateMedian requires an array of numbers"); } } + const middleIndex = Math.floor(list.length / 2); const sortedList = list.sort((a, b) => a - b); if (list.length % 2 === 0) { const median = (sortedList[middleIndex] + sortedList[middleIndex - 1]) / 2; return median; } else { - const median = sortedList.splice(middleIndex, 1)[0]; - return median; + //const median = sortedList.splice(middleIndex, 1)[0]; + return sortedList[middleIndex]; } } From 0a0c4d52d2926f62706783d7fc2bd72ab93e93f1 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 01:36:31 +0000 Subject: [PATCH 07/51] edited a code for sorting the array and saving it with out changing the original array, test passed --- Sprint-1/fix/median.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 46d09e83c..beeebd932 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -22,7 +22,7 @@ function calculateMedian(list) { } } const middleIndex = Math.floor(list.length / 2); - const sortedList = list.sort((a, b) => a - b); + const sortedList = [...list].sort((a, b) => a - b); if (list.length % 2 === 0) { const median = (sortedList[middleIndex] + sortedList[middleIndex - 1]) / 2; return median; From 3fdbba51348707685b585a1a7140de3410034fde Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 02:08:41 +0000 Subject: [PATCH 08/51] added a test for an array with no duplicate. --- Sprint-1/implement/dedupe.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index d7c8e3d8e..a8526608e 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -21,8 +21,13 @@ test.todo("given an empty array, it returns an empty array"); // Given an array with no duplicates // When passed to the dedupe function // Then it should return a copy of the original array +test("when passed an array with no duplicate", () => { + const array = [1, 2, 3, 4]; + dedupe(array); + expect(dedupe(array)).toEqual([1, 2, 3, 4]); +}); // Given an array of strings or numbers // When passed to the dedupe function -// Then it should return a new array with duplicates removed while preserving the +// Then it should return a new array with duplicates removed while preserving the // first occurrence of each element from the original array. From 1ac1a8cd919ed532a3eda24b9f5f503b3f5c33b6 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 02:09:22 +0000 Subject: [PATCH 09/51] added a return. test passed --- Sprint-1/implement/dedupe.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..deb1c5f0e 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,4 @@ -function dedupe() {} +function dedupe(array) { + return array; +} +module.exports = dedupe; From a8c8e5b447c8cb2d3a2d26a25b3d0022fae11ae7 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 03:44:03 +0000 Subject: [PATCH 10/51] wrote test for number and strings and test failed --- Sprint-1/implement/dedupe.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index a8526608e..2db4a7ab7 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -31,3 +31,13 @@ test("when passed an array with no duplicate", () => { // When passed to the dedupe function // Then it should return a new array with duplicates removed while preserving the // first occurrence of each element from the original array. +test("when passed an array of duplicate numbers", () => { + expect(dedupe([1, 1, 2])).toEqual([1, 2]); + expect(dedupe([1, 1, 2, 2, 2, 3])).toEqual([1, 2, 3]); + expect(dedupe([1, 1, 1, 3, 3, 4, 4])).toEqual([1, 3, 4]); +}); + +test("when passed an array of duplicate characters", () => { + expect(dedupe(["a", "a", "b", "b", "b", "c"])).toEqual(["a", "b", "c"]); + expect(dedupe(["c", "c", "e", "e", "z", "z"])).toEqual(["c", "e", "z"]); +}); From 8b2277a21a561582c49c4f831f3d238c7452e8f5 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 03:44:39 +0000 Subject: [PATCH 11/51] wrote a code to make the test passed .test passed --- Sprint-1/implement/dedupe.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index deb1c5f0e..e8c072b21 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,4 +1,12 @@ function dedupe(array) { - return array; + const withOutDup = []; + for (let i = 0; i < array.length; i++) { + const itemArray = array[i]; + if (!withOutDup.includes(itemArray)) { + withOutDup.push(itemArray); + } + } + + return withOutDup; } module.exports = dedupe; From 7a8e98b5f6ca3cd8c3f7a85c2a263e1bcdc0acc0 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 03:50:08 +0000 Subject: [PATCH 12/51] added a test for test.todo. test passed --- Sprint-1/implement/dedupe.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 2db4a7ab7..35a7a298b 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -16,7 +16,12 @@ E.g. dedupe([1, 2, 1]) returns [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.todo("given an empty array, it returns an empty array"); +test("when passed an emptyarray", () => { + const array = []; + dedupe(array); + expect(dedupe(array)).toEqual([]); +}); // Given an array with no duplicates // When passed to the dedupe function From 20f698c1af6d3a3f7dea35943e6555875ad0a5bb Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 15:51:44 +0000 Subject: [PATCH 13/51] wrote a test to replace the test todo test passed --- Sprint-1/implement/describe-median.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index e7d18a264..7bca79e77 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -22,6 +22,9 @@ const describeMedian = require("./describe-median.js"); // Then it should return "The median is " followed by the median // Delete this test.todo and replace it with a test. test.todo('given [1, 2, 3], returns "The median is 2"'); +test("returns the correct median when given [1,2,3]", () => { + expect(describeMedian([1, 2, 3])).toEqual(2); +}); // Given an empty array // When passed to describeMedian From 720fdaf54dd1c187f2d4d6c6b8b1d6cbea7022e4 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sat, 31 Oct 2026 15:52:55 +0000 Subject: [PATCH 14/51] wrote a code that calles the function calculate median .test passed --- Sprint-1/implement/describe-median.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/describe-median.js b/Sprint-1/implement/describe-median.js index 3381cfc0a..5faefb142 100644 --- a/Sprint-1/implement/describe-median.js +++ b/Sprint-1/implement/describe-median.js @@ -20,6 +20,9 @@ function calculateMedian(list) { } // Implement this function. See describe-median.test.js for the acceptance criteria. -function describeMedian(list) {} +function describeMedian(list) { + let result = calculateMedian(list); + return result; +} module.exports = describeMedian; From 30cf7cd1c8e71875128a2bfde094c6c0b657a61c Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 12:18:43 +0000 Subject: [PATCH 15/51] edited some tests and added some more test,test failed --- Sprint-1/implement/describe-median.test.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/describe-median.test.js b/Sprint-1/implement/describe-median.test.js index 7bca79e77..6acf2be0e 100644 --- a/Sprint-1/implement/describe-median.test.js +++ b/Sprint-1/implement/describe-median.test.js @@ -21,7 +21,6 @@ const describeMedian = require("./describe-median.js"); // When passed to describeMedian // Then it should return "The median is " followed by the median // Delete this test.todo and replace it with a test. -test.todo('given [1, 2, 3], returns "The median is 2"'); test("returns the correct median when given [1,2,3]", () => { expect(describeMedian([1, 2, 3])).toEqual(2); }); @@ -29,7 +28,26 @@ test("returns the correct median when given [1,2,3]", () => { // Given an empty array // When passed to describeMedian // Then it should return "Could not calculate a median: calculateMedian requires a non-empty array" - +test("returns an error message when given an empty array", () => { + expect(describeMedian([])).toEqual( + "Could not calculate a median:calculateMedian requires a non-empty array" + ); +}); // Given something that isn't an array of numbers, e.g. "banana" // When passed to describeMedian // Then it should return "Could not calculate a median: calculateMedian requires an array of numbers" +test("returns an error message when given a string of array", () => { + expect(describeMedian(["banana"])).toEqual( + "Could not calculate a median:calculateMedian requires an array of numbers" + ); +}); +test("return an error message when given a number", () => { + expect(describeMedian(123)).toEqual( + "Could not calculate a median:calculateMedian requires an array of numbers" + ); +}); +test("return an error message when given list of strings of array", () => { + expect(describeMedian(["one", "two", "three"])).toEqual( + "Could not calculate a median:calculateMedian requires an array of numbers" + ); +}); From f8736d957b9ce7c1572fee0f9b4a86c12aa4de1b Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 12:19:30 +0000 Subject: [PATCH 16/51] added try and catch block to return the error message. test passed --- Sprint-1/implement/describe-median.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/describe-median.js b/Sprint-1/implement/describe-median.js index 5faefb142..d21712eec 100644 --- a/Sprint-1/implement/describe-median.js +++ b/Sprint-1/implement/describe-median.js @@ -21,8 +21,14 @@ function calculateMedian(list) { // Implement this function. See describe-median.test.js for the acceptance criteria. function describeMedian(list) { - let result = calculateMedian(list); - return result; + try { + let result = calculateMedian(list); + return result; + } catch (error) { + // console.error(`Could not calculate a median:${error.message}`); + return `Could not calculate a median:${error.message}`; + //throw error; + } } module.exports = describeMedian; From ab03db593e4433514c8afb47d994fc095e655881 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 12:52:15 +0000 Subject: [PATCH 17/51] implemented a function that finds the largest numerical element of an array --- Sprint-1/implement/max.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..d5578ad1b 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,11 @@ function findMax(elements) { + let max = elements[0]; + for (let num of elements) { + if (max < num) { + max = num; + } + } + return max; } module.exports = findMax; From 3d22657b3ec78c69b84687b885359e0facbdd129 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 13:21:42 +0000 Subject: [PATCH 18/51] added a test that should return -Infinity when given empty array.test failed --- Sprint-1/implement/max.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index ff3fbb5e5..fbbbc038f 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -17,6 +17,9 @@ const findMax = require("./max.js"); // Then it should return -Infinity // Delete this test.todo and replace it with a test. test.todo("given an empty array, returns -Infinity"); +test("return -Infinity when given an Empty array", () => { + expect(findMax([])).toEqual(-Infinity); +}); // Given an array with one number // When passed to the max function From fd5644f49ebf96b5e1e647685e3fd174515e02d2 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 13:23:11 +0000 Subject: [PATCH 19/51] added Math.max to the code so it can return -Infinity,test passed --- Sprint-1/implement/max.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index d5578ad1b..5e5f30a33 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,11 +1,11 @@ function findMax(elements) { - let max = elements[0]; - for (let num of elements) { - if (max < num) { - max = num; - } - } - return max; + // let max = elements[0]; + //for (let num of elements) { + //if (max < num) { + // max = num; + //} + //} + return Math.max(...elements); } module.exports = findMax; From f15e553e704914f816173496d66152d2151490d7 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 13:35:22 +0000 Subject: [PATCH 20/51] addeda a test that reurn the nember when passed one number --- Sprint-1/implement/max.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index fbbbc038f..533afc477 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -16,7 +16,6 @@ const findMax = require("./max.js"); // 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"); test("return -Infinity when given an Empty array", () => { expect(findMax([])).toEqual(-Infinity); }); @@ -24,6 +23,10 @@ test("return -Infinity when given an Empty array", () => { // Given an array with one number // When passed to the max function // Then it should return that number +test("return the number when given one number", () => { + expect(findMax([10])).toEqual(10); + expect(findMax([1])).toEqual(1); +}); // Given an array with both positive and negative numbers // When passed to the max function From f5e48dcd79cd9c5bd8cec8bd1241ccd33be7ef03 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 13:46:37 +0000 Subject: [PATCH 21/51] added to tests that would return the largest number when given -ve and +ve number and only -ve number --- Sprint-1/implement/max.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 533afc477..fabbf1070 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -31,10 +31,18 @@ test("return the number when given one number", () => { // Given an array with both positive and negative numbers // When passed to the max function // Then it should return the largest number overall +test("return the largest number when given negative and posetive numbers", () => { + expect(findMax([10, -10, -3, 4])).toEqual(10); + expect(findMax([-10, 2, -5, 6, 9])).toEqual(9); +}); // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero +test("returns closest one to zero when given array of negative numbers", () => { + expect(findMax([-1, -5, -2, 10])).toEqual(-1); + expect(findMax([-5 - 10, -100, -20])).toEqual(-5); +}); // Given an array with decimal numbers // When passed to the max function From cd439b7c551c6e1849d0e577cd148952d787a4ca Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 14:02:46 +0000 Subject: [PATCH 22/51] added a test for largest decimal numbers and test passed --- Sprint-1/implement/max.test.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index fabbf1070..47ec6e112 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -40,13 +40,18 @@ test("return the largest number when given negative and posetive numbers", () => // When passed to the max function // Then it should return the closest one to zero test("returns closest one to zero when given array of negative numbers", () => { - expect(findMax([-1, -5, -2, 10])).toEqual(-1); - expect(findMax([-5 - 10, -100, -20])).toEqual(-5); + expect(findMax([-1, -5, -2, -10])).toEqual(-1); + expect(findMax([-5, -10, -100, -20])).toEqual(-5); }); // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number +test("return the largest decimal number when given decimal numbers in an array", () => { + expect(findMax([0.01, 0.02, 2.5, 2.9])).toEqual(2.9); + expect(findMax([3.5, 2.5, 2.9])).toEqual(3.5); + expect(findMax([10.1, 9, 3, 11])).toEqual(11); +}); // Given an array containing a value that isn't a number // When passed to the max function From f2e48713e4c730ed4107a602fadf05ee10b9a766 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 14:13:07 +0000 Subject: [PATCH 23/51] added test that throws an error when given a value that is not number, test failed --- Sprint-1/implement/max.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 47ec6e112..2fbcca8a2 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -56,6 +56,11 @@ test("return the largest decimal number when given decimal numbers in an array", // Given an array containing a value that isn't a number // When passed to the max function // Then it should throw Error("findMax requires an array of numbers") +test("return error when given an array containg non number value", () => { + expect(() => findMax(["a", "b", "c"])).toThrow( + "findMax requaires 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 From ea1f770269925b9a4a4d16e7a92903c4c861b054 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 14:48:08 +0000 Subject: [PATCH 24/51] added atest that throws an error when given non number value in an array --- Sprint-1/implement/max.test.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 2fbcca8a2..6f3d5290f 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -56,12 +56,35 @@ test("return the largest decimal number when given decimal numbers in an array", // Given an array containing a value that isn't a number // When passed to the max function // Then it should throw Error("findMax requires an array of numbers") +test("return error when given an array containg non number value", () => { + expect(() => findMax(["a", 2, "c"])).toThrow( + "findMax requires an array of numbers" + ); +}); test("return error when given an array containg non number value", () => { expect(() => findMax(["a", "b", "c"])).toThrow( - "findMax requaires an array of numbers" + "findMax requires an array of numbers" + ); +}); +test("return error when given an array containg non number value", () => { + expect(() => findMax([1, "hallo", 2])).toThrow( + "findMax requires an array of numbers" + ); +}); +test("return error when given an array containg non number value", () => { + expect(() => findMax(["a", , "c"])).toThrow( + "findMax requires an array of numbers" + ); +}); +test("return error when given an array containg non number value", () => { + expect(() => findMax([1, , 2])).toThrow( + "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 // Then it should throw Error("findMax requires an array of numbers") +test("return error when given non array values", () => { + expect(() => findMax("hey")).toThrow("findMax requires an array of numbers"); +}); From 2d230bf74d89c1cf9f3508ea41aa41a616f028f3 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 14:49:10 +0000 Subject: [PATCH 25/51] deleted the commented code and added the for loop to check on the value of the array if they are numbers or not,test passed --- Sprint-1/implement/max.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 5e5f30a33..3db4913a8 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,10 +1,9 @@ function findMax(elements) { - // let max = elements[0]; - //for (let num of elements) { - //if (max < num) { - // max = num; - //} - //} + for (let num of elements) { + if (typeof num !== "number") { + throw new Error("findMax requires an array of numbers"); + } + } return Math.max(...elements); } From 1f598f11e42ecbd3b918b1445bbe519b2f6c1eb1 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 15:01:43 +0000 Subject: [PATCH 26/51] wrote test to return an error when given non array arguments,two test failed --- Sprint-1/implement/max.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 6f3d5290f..7f595b755 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -88,3 +88,9 @@ test("return error when given an array containg non number value", () => { test("return error when given non array values", () => { expect(() => findMax("hey")).toThrow("findMax requires an array of numbers"); }); +test("return error when given non array values that is number", () => { + expect(() => findMax(42)).toThrow("findMax requires an array of numbers"); +}); +test("return error when given no argument", () => { + expect(() => findMax()).toThrow("findMax requires an array of numbers"); +}); From 73325f6ea1017dc158f85689416aba9237c08d62 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 15:02:27 +0000 Subject: [PATCH 27/51] added a code that throws an error when non array aruments passed --- Sprint-1/implement/max.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 3db4913a8..251ff4cd6 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,7 @@ function findMax(elements) { + if (!Array.isArray(elements)) { + throw new Error("findMax requires an array of numbers"); + } for (let num of elements) { if (typeof num !== "number") { throw new Error("findMax requires an array of numbers"); From 8ef5244fcbc47674ba30905def5ce379a1fbe524 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 15:20:47 +0000 Subject: [PATCH 28/51] implemented a function calculateMean --- Sprint-1/implement/mean.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index 36909ea1f..c05569fb6 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,3 +1,9 @@ -function calculateMean(list) {} +function calculateMean(list) { + let total = 0; + for (let num of list) { + total += num; + } + return (mean = total / list.length); +} module.exports = calculateMean; From aae967968081f8ea9689e86dab03d2f59f99c6c6 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 15:21:22 +0000 Subject: [PATCH 29/51] added a test for the test .todo test passed --- Sprint-1/implement/mean.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 847b88676..358b329dc 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -24,6 +24,9 @@ const calculateMean = require("./mean.js"); // 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("returns calculated mean when given array of numbers", () => { + expect(calculateMean([1, 2, 6])).toEqual(3); +}); // Given an array with a single number // When passed to calculateMean From 90f3ec4a11eb0c97a48aa9f784de37ee7f137d79 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 15:32:05 +0000 Subject: [PATCH 30/51] added two test for asingle number and for -ve and +ve number in an array, one test failed --- Sprint-1/implement/mean.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 358b329dc..2df11a356 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -23,7 +23,7 @@ const calculateMean = require("./mean.js"); // 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("returns calculated mean when given array of numbers", () => { expect(calculateMean([1, 2, 6])).toEqual(3); }); @@ -31,10 +31,18 @@ test("returns calculated mean when given array of numbers", () => { // Given an array with a single number // When passed to calculateMean // Then it should return that number +test("returns calculated mean when given array of numbers", () => { + expect(calculateMean([1])).toEqual(1); + expect(calculateMean([10])).toEqual(10); +}); // Given an array containing negative or decimal numbers // When passed to calculateMean // Then it should return the correct mean +test("returns calculated mean when given array of +ve and -ve numbers", () => { + expect(calculateMean([5, -2, -3, 4])).toEqual(1); + expect(calculateMean([-2, -1, 5])).toEqual(0.66); +}); // Given an empty array // When passed to calculateMean From 7edbeee8112c231af871d23ebf2a7232481c9ee9 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 15:51:33 +0000 Subject: [PATCH 31/51] added a test that returns an error when given empty array --- Sprint-1/implement/mean.test.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 2df11a356..8b43c1ac9 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -39,14 +39,20 @@ test("returns calculated mean when given array of numbers", () => { // Given an array containing negative or decimal numbers // When passed to calculateMean // Then it should return the correct mean -test("returns calculated mean when given array of +ve and -ve numbers", () => { +test("returns calculated mean when given array of +ve and -ve numbers and deciamls are given", () => { expect(calculateMean([5, -2, -3, 4])).toEqual(1); - expect(calculateMean([-2, -1, 5])).toEqual(0.66); + expect(calculateMean([-2, -1, 5])).toEqual(0.6666666666666666); + expect(calculateMean([1.5, 2.4, 5.6])).toEqual(3.1666666666666665); }); // Given an empty array // When passed to calculateMean // Then it should throw Error("calculateMean requires a non-empty array") +test("returns an error when given an empty array", () => { + 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 From 35767333fa33d9a8cf5af54e62af4c3e9b34d786 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 15:53:04 +0000 Subject: [PATCH 32/51] added a code that throws an error when empty array is given --- Sprint-1/implement/mean.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index c05569fb6..bed529a5b 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,9 +1,12 @@ function calculateMean(list) { - let total = 0; - for (let num of list) { - total += num; + if (list.length === 0) { + throw new Error("calculateMean requires a non-empty array"); + let total = 0; + for (let num of list) { + total += num; + } + return (mean = total / list.length); } - return (mean = total / list.length); } module.exports = calculateMean; From e460491ff5a68c3920384ec833d48e6849301103 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 16:32:42 +0000 Subject: [PATCH 33/51] added a test for a given value that is non array.test failed --- Sprint-1/implement/mean.test.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 8b43c1ac9..076315398 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -39,7 +39,7 @@ test("returns calculated mean when given array of numbers", () => { // Given an array containing negative or decimal numbers // When passed to calculateMean // Then it should return the correct mean -test("returns calculated mean when given array of +ve and -ve numbers and deciamls are given", () => { +test("returns calculated mean when given array of +ve and -ve numbers and decimal numbers are given", () => { expect(calculateMean([5, -2, -3, 4])).toEqual(1); expect(calculateMean([-2, -1, 5])).toEqual(0.6666666666666666); expect(calculateMean([1.5, 2.4, 5.6])).toEqual(3.1666666666666665); @@ -57,7 +57,21 @@ test("returns an error when given an 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("throws an error when given an empty array", () => { + expect(() => calculateMean("banana")).toThrow( + "calculateMean requires an array of numbers" + ); +}); +test("throws an error when given a number", () => { + expect(() => calculateMean(42)).toThrow( + "calculateMean requires an array of numbers" + ); +}); +test("throws an error when given a null", () => { + expect(() => calculateMean(null)).toThrow( + "calculateMean requires an array of numbers" + ); +}); // Given no argument at all // When passed to calculateMean // Then it should throw Error("calculateMean requires an array of numbers") From 251329ca2eeb2c100daa28d3fb49fdb15bc8162a Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 16:35:15 +0000 Subject: [PATCH 34/51] added the code to check if the argument is array or not, test passed --- Sprint-1/implement/mean.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index bed529a5b..49147ece2 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -1,12 +1,15 @@ 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 num of list) { - total += num; - } - return (mean = total / list.length); } + let total = 0; + for (let num of list) { + total += num; + } + return (mean = total / list.length); } module.exports = calculateMean; From 8101cc21e9a32e3cadb18fe6747cc4d245f633e6 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 16:50:55 +0000 Subject: [PATCH 35/51] addeda test for no argument passed to the functon, test passed --- Sprint-1/implement/mean.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 076315398..dd7678e9e 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -75,6 +75,11 @@ test("throws an error when given a null", () => { // Given no argument at all // When passed to calculateMean // Then it should throw Error("calculateMean requires an array of numbers") +test("throws an error when given no argument", () => { + 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 From 3207a97f378527053739b388c7edbd5614a19b06 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 17:07:31 +0000 Subject: [PATCH 36/51] added a test for a n array containing non number value ,test failed --- Sprint-1/implement/mean.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index dd7678e9e..76ef6e71b 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -84,3 +84,9 @@ test("throws an error when given no argument", () => { // 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("throws an error when given an array containing a non number value", () => { + expect(() => calculateMean([1, "2", 3])).toThrow( + "calculateMean requires an array of numbers" + ); +}); From 1da066ef3fc05a76e5849bb023abe2964c5fd966 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 17:19:56 +0000 Subject: [PATCH 37/51] added a code that throws error when an array containing a non number value --- Sprint-1/implement/mean.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/mean.js b/Sprint-1/implement/mean.js index 49147ece2..2e14ef629 100644 --- a/Sprint-1/implement/mean.js +++ b/Sprint-1/implement/mean.js @@ -5,8 +5,13 @@ function calculateMean(list) { if (list.length === 0) { throw new Error("calculateMean requires a non-empty array"); } + for (const item of list) { + if (typeof item !== "number") { + throw new Error("calculateMean requires an array of numbers"); + } + } let total = 0; - for (let num of list) { + for (const num of list) { total += num; } return (mean = total / list.length); From be6ec8dab149e3e78aa1790eb39afd8354c51c7c Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 17:43:52 +0000 Subject: [PATCH 38/51] added a test for an argument that is not array --- Sprint-1/implement/mean.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/mean.test.js b/Sprint-1/implement/mean.test.js index 76ef6e71b..f4b731c9f 100644 --- a/Sprint-1/implement/mean.test.js +++ b/Sprint-1/implement/mean.test.js @@ -72,6 +72,11 @@ test("throws an error when given a null", () => { "calculateMean requires an array of numbers" ); }); +test("throws an error when given a {}", () => { + expect(() => calculateMean({})).toThrow( + "calculateMean requires an array of numbers" + ); +}); // Given no argument at all // When passed to calculateMean // Then it should throw Error("calculateMean requires an array of numbers") From 9ba29de1edd66c312d9aa8030ef1beea876619bc Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 18:42:44 +0000 Subject: [PATCH 39/51] implement the function sum --- Sprint-1/implement/sum.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..84e45e753 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,9 @@ function sum(elements) { + let total = 0; + for (const num of elements) { + total += num; + } + return total; } module.exports = sum; From 1cac38e4ca828b08efc705828bb7e65fbc4db192 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 18:47:05 +0000 Subject: [PATCH 40/51] wrote a test for an empty array that should return zero.test passed --- Sprint-1/implement/sum.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index a288e0f0a..f97286047 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -13,7 +13,10 @@ const sum = require("./sum.js"); // Given an empty array // When passed to the sum function // Then it should return 0 -test.todo("given an empty array, returns 0") +test.todo("given an empty array, returns 0"); +test("should return 0 when given an empty array", () => { + expect(sum([])).toEqual(0); +}); // Given an array with just one number // When passed to the sum function From 43647bbe9b3ced85dbf18604539cdc21909ebd58 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 20:36:28 +0000 Subject: [PATCH 41/51] wrote a test for an array with one number to return one number,test passed --- Sprint-1/implement/sum.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index f97286047..51a4862da 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -13,7 +13,6 @@ const sum = require("./sum.js"); // Given an empty array // When passed to the sum function // Then it should return 0 -test.todo("given an empty array, returns 0"); test("should return 0 when given an empty array", () => { expect(sum([])).toEqual(0); }); @@ -21,7 +20,11 @@ test("should return 0 when given an empty array", () => { // Given an array with just one number // When passed to the sum function // Then it should return that number - +test("should return the number when given one number", () => { + expect(sum([10])).toEqual(10); + expect(sum([-1])).toEqual(-1); + expect(sum([0])).toEqual(0); +}); // Given an array containing negative numbers // When passed to the sum function // Then it should still return the correct total sum From 49baa11d8745ac4511bab2e89584b83ccb892e8c Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 20:45:00 +0000 Subject: [PATCH 42/51] wrote a test for an array with negative numbers, test passed --- Sprint-1/implement/sum.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index 51a4862da..7ca0080ac 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -28,6 +28,11 @@ test("should return the number when given one number", () => { // Given an array containing negative numbers // When passed to the sum function // Then it should still return the correct total sum +test("should return the number when given negative numbers ", () => { + expect(sum([10, -4, 5, 7])).toEqual(18); + expect(sum([-3, -4, -6, -9])).toEqual(-22); + expect(sum([7, -9, 2, 1])).toEqual(1); +}); // Given an array with decimal/float numbers // When passed to the sum function From dab9188481a72a817ea388d4230cbe85d22f3cbe Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 23:06:35 +0000 Subject: [PATCH 43/51] added a code that throws an error when a non number value is in the array --- Sprint-1/implement/sum.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 84e45e753..17d334948 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,9 @@ function sum(elements) { + for (const num of elements) { + if (typeof num !== "number") { + throw new Error("sum requires an array of numbers"); + } + } let total = 0; for (const num of elements) { total += num; From 12e8cb0b5c398dbe61d9db0dc663005de1f40ea5 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 23:08:20 +0000 Subject: [PATCH 44/51] added a test for adding decimal and throwing and error if non number value is found --- Sprint-1/implement/sum.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index 7ca0080ac..dd7665a8b 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -37,10 +37,20 @@ test("should return the number when given negative numbers ", () => { // Given an array with decimal/float numbers // When passed to the sum function // Then it should return the correct total sum +test("should return the number when given decimal number", () => { + expect(sum([2.5, 3.4, 5.7, 2])).toEqual(13.6); + expect(sum([1, 1.5, 2.5, 6.3])).toEqual(11.3); + expect(sum([2.3, 2.7, 7.4, 5.5])).toEqual(17.9); +}); // Given an array containing a value that isn't a number // When passed to the sum function // Then it should throw Error("sum requires an array of numbers") +test("should throw an error when argument is passed that is non number", () => { + expect(() => sum([1, 2, "hi", 3, "hey"])).toThrow( + "sum 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 sum function From c4a048800e6f263dd5137ce4014b40bc03bfb1d8 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 23:32:12 +0000 Subject: [PATCH 45/51] added tests that throw error when the argument is non array --- Sprint-1/implement/sum.test.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index dd7665a8b..dfa22cc7d 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -38,7 +38,7 @@ test("should return the number when given negative numbers ", () => { // When passed to the sum function // Then it should return the correct total sum test("should return the number when given decimal number", () => { - expect(sum([2.5, 3.4, 5.7, 2])).toEqual(13.6); + expect(sum([2.5, 3.4, 5.5, 2])).toEqual(13.4); expect(sum([1, 1.5, 2.5, 6.3])).toEqual(11.3); expect(sum([2.3, 2.7, 7.4, 5.5])).toEqual(17.9); }); @@ -55,3 +55,12 @@ test("should throw an error when argument is passed that is non number", () => { // Given something that isn't an array at all, such as "hey", 42 or no argument // When passed to the sum function // Then it should throw Error("sum requires an array of numbers") +test("should throw an error when argument 'hey'is passed", () => { + expect(() => sum("hey")).toThrow("sum requires an array of numbers"); +}); +test("should throw an error when argument 42 is passed", () => { + expect(() => sum(42)).toThrow("sum requires an array of numbers"); +}); +test("should throw an error when no argument is passed", () => { + expect(() => sum()).toThrow("sum requires an array of numbers"); +}); From 7165d344936ad24e42c07256cc440599a54028d9 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 1 Nov 2026 23:37:19 +0000 Subject: [PATCH 46/51] added a code that would throw error when element is not array --- Sprint-1/implement/sum.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 17d334948..3cbe2891b 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,7 @@ function sum(elements) { + if (!Array.isArray(elements)) { + throw new Error("sum requires an array of numbers"); + } for (const num of elements) { if (typeof num !== "number") { throw new Error("sum requires an array of numbers"); From 31a874cf061fe48c8cce65aaa6acddf38656ab92 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 2 Nov 2026 00:16:09 +0000 Subject: [PATCH 47/51] refractored the code . the test still passes --- Sprint-1/refactor/includes.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..e78b21d70 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,9 +1,8 @@ // Refactor the implementation of includes to use a for...of loop function includes(list, target) { - for (let index = 0; index < list.length; index++) { - const element = list[index]; - if (element === target) { + for (let num of list) { + if (num === target) { return true; } } From 57a5cc3ea15352fe18528fda3347c394d403f751 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Thu, 5 Nov 2026 20:26:45 +0000 Subject: [PATCH 48/51] changed itemArray ti item as advised --- Sprint-1/implement/dedupe.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index e8c072b21..4cd6d23e7 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,9 +1,9 @@ function dedupe(array) { const withOutDup = []; for (let i = 0; i < array.length; i++) { - const itemArray = array[i]; - if (!withOutDup.includes(itemArray)) { - withOutDup.push(itemArray); + const item = array[i]; + if (!withOutDup.includes(item)) { + withOutDup.push(item); } } From ee47d72e8c375fc3703cd9d1615032d9313fddb9 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Thu, 5 Nov 2026 20:27:34 +0000 Subject: [PATCH 49/51] added two taste cases for unordered number and character,both test passed --- Sprint-1/implement/dedupe.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 35a7a298b..6ead2f900 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -46,3 +46,14 @@ test("when passed an array of duplicate characters", () => { expect(dedupe(["a", "a", "b", "b", "b", "c"])).toEqual(["a", "b", "c"]); expect(dedupe(["c", "c", "e", "e", "z", "z"])).toEqual(["c", "e", "z"]); }); +test("when passed an array of duplicate unordered numbers ", () => { + expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]); +}); +test("when passed an array of duplicate unordered characters ", () => { + expect(dedupe(["f", "a", "a", "k", "k", "c", "c"])).toEqual([ + "f", + "a", + "k", + "c", + ]); +}); From b560e2cf9e9b0ecb087651b310727fdb19ff1383 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Thu, 5 Nov 2026 21:34:15 +0000 Subject: [PATCH 50/51] changed itemArray to item as advised --- Sprint-1/implement/dedupe.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index e8c072b21..4cd6d23e7 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,9 +1,9 @@ function dedupe(array) { const withOutDup = []; for (let i = 0; i < array.length; i++) { - const itemArray = array[i]; - if (!withOutDup.includes(itemArray)) { - withOutDup.push(itemArray); + const item = array[i]; + if (!withOutDup.includes(item)) { + withOutDup.push(item); } } From 58d46b53e326d2422a1034b3074d22727bfc4b1b Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Thu, 5 Nov 2026 21:35:15 +0000 Subject: [PATCH 51/51] added two test cases for unordered number and character,both test passed --- Sprint-1/implement/dedupe.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 35a7a298b..6ead2f900 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -46,3 +46,14 @@ test("when passed an array of duplicate characters", () => { expect(dedupe(["a", "a", "b", "b", "b", "c"])).toEqual(["a", "b", "c"]); expect(dedupe(["c", "c", "e", "e", "z", "z"])).toEqual(["c", "e", "z"]); }); +test("when passed an array of duplicate unordered numbers ", () => { + expect(dedupe([5, 1, 1, 2, 3, 2, 5, 8])).toEqual([5, 1, 2, 3, 8]); +}); +test("when passed an array of duplicate unordered characters ", () => { + expect(dedupe(["f", "a", "a", "k", "k", "c", "c"])).toEqual([ + "f", + "a", + "k", + "c", + ]); +});