From 575c93913d981c14c0e451ee7df279e0857550d5 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Mon, 23 Feb 2026 21:24:13 +0000 Subject: [PATCH 01/20] filtered and sorted a copy of the original list --- Sprint-1/fix/median.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..43f6415df 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,9 +6,15 @@ // or 'list' has mixed values (the function is expected to sort only numbers). function calculateMedian(list) { - const middleIndex = Math.floor(list.length / 2); + let listCopy=[...list] + let filteredList=listCopy.filter(x=>+x) + let sortedList=filteredList.sort((a,b)=>a-b) + const middleIndex = Math.floor(sortedList.length / 2); const median = list.splice(middleIndex, 1)[0]; - return median; + return middleIndex } +console.log(calculateMedian([5,1,"g,",3])); + + module.exports = calculateMedian; From 8ca70c315a7e8498817a7d6533ae1ce23070814e Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:08:25 +0000 Subject: [PATCH 02/20] Refactor calculateMedian function to handle non-array inputs and improve filtering of numeric values --- Sprint-1/fix/median.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index 43f6415df..3255aadcd 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -6,15 +6,29 @@ // or 'list' has mixed values (the function is expected to sort only numbers). function calculateMedian(list) { - let listCopy=[...list] - let filteredList=listCopy.filter(x=>+x) - let sortedList=filteredList.sort((a,b)=>a-b) + if (!Array.isArray(list)) { + return null; + } + + let listCopy = [...list]; + let filteredList = listCopy.filter((x) => typeof x === "number"); + let sortedList = filteredList.sort((a, b) => a - b); const middleIndex = Math.floor(sortedList.length / 2); - const median = list.splice(middleIndex, 1)[0]; - return middleIndex + + if (filteredList.length === 0) { + return null; + } + + let median = 0; + if (sortedList.length % 2 === 0) { + median = (sortedList[middleIndex - 1] + sortedList[middleIndex]) / 2; + } else { + median = sortedList[middleIndex]; + } + + return median; } -console.log(calculateMedian([5,1,"g,",3])); module.exports = calculateMedian; From 0656e3b8d1201305813d358a345b353210f3b579 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:16:41 +0000 Subject: [PATCH 03/20] Add test for findMax function to return Infinity for empty array --- Sprint-1/implement/max.js | 5 ++++- Sprint-1/implement/max.test.js | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..d11ccc501 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,7 @@ function findMax(elements) { + if(elements.length===0){ + return Infinity + } } -module.exports = findMax; +module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 82f18fd88..0a035f526 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -12,11 +12,16 @@ We have set things up already so that this file can see your function from the o const findMax = require("./max.js"); -// Given an empty array +// 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"); +test("given an empty array, returns -Infinity",()=>{ + const array=[] + const currentOutput=findMax(array) + const targetOutput=Infinity + expect(currentOutput).toEqual(targetOutput) +}); // Given an array with one number // When passed to the max function From b50166ecdb247b518e9de865788b78bfaac84039 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:20:15 +0000 Subject: [PATCH 04/20] Implement findMax function to return the maximum number from an array and add corresponding test cases --- Sprint-1/implement/max.js | 3 +++ Sprint-1/implement/max.test.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index d11ccc501..2ed3dad29 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -2,6 +2,9 @@ function findMax(elements) { if(elements.length===0){ return Infinity } + if(elements.length===1){ + return elements[0] + } } module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 0a035f526..6a5ef41b8 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -26,11 +26,18 @@ test("given an empty array, returns -Infinity",()=>{ // 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", () => { + const array = [3]; + const currentOutput = findMax(array); + const targetOutput = 3; + expect(currentOutput).toEqual(targetOutput); +}); // 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 just negative numbers // When passed to the max function // Then it should return the closest one to zero From 99d142133807e39769ade59fe9195dfff3e84c8e Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:42:20 +0000 Subject: [PATCH 05/20] Refactor findMax function and add test for handling both positive and negative numbers --- Sprint-1/implement/max.js | 20 +++++++++++++------- Sprint-1/implement/max.test.js | 8 +++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 2ed3dad29..4e265636e 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,10 +1,16 @@ function findMax(elements) { - if(elements.length===0){ - return Infinity - } - if(elements.length===1){ - return elements[0] - } + if (elements.length === 0) { + return Infinity; + } + + if (elements.length === 1) { + return elements[0]; + } + const sortedElements = elements.sort((a, b) => a - b); + + return sortedElements.reduce((a,b)=>Math.max(a,b)) } -module.exports = findMax; +console.log(findMax([3, -5, 7, -9])); + +module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 6a5ef41b8..092daf5ef 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -36,12 +36,18 @@ test("given an array with one number, returns -that 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("given an array with both positive and negative numbers, returns -the largest number overall ",()=>{ + const array = [3,-5,7,-9]; + const currentOutput = findMax(array); + const targetOutput = 7; + expect(currentOutput).toEqual(targetOutput); +}) // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero + // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number From 80d3cb0985ec9475866eb579aecaeddcfe9d4e30 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:45:51 +0000 Subject: [PATCH 06/20] Add test for findMax function to handle arrays with only negative numbers --- Sprint-1/implement/max.js | 2 +- Sprint-1/implement/max.test.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 4e265636e..0c4fb9707 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -11,6 +11,6 @@ function findMax(elements) { return sortedElements.reduce((a,b)=>Math.max(a,b)) } -console.log(findMax([3, -5, 7, -9])); +console.log(findMax([-5, -1, -7, -3])); module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 092daf5ef..e328b319a 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -46,7 +46,12 @@ test("given an array with both positive and negative numbers, returns -the large // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero - +test("given an array with just negative numbers, return the closest one to 0",()=>{ + const array=[-5,-1,-7,-3] + const currentOutput=findMax(array) + const targetOutput=-1 + expect(currentOutput).toEqual(targetOutput) +}) // Given an array with decimal numbers // When passed to the max function From ef647c61c18df660de0785ccb958af79038a6cc8 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:49:10 +0000 Subject: [PATCH 07/20] Update tests for findMax function to include decimal numbers and adjust negative number scenarios --- Sprint-1/implement/max.test.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index e328b319a..7ea66f293 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -37,7 +37,7 @@ test("given an array with one number, returns -that number", () => { // When passed to the max function // Then it should return the largest number overall test("given an array with both positive and negative numbers, returns -the largest number overall ",()=>{ - const array = [3,-5,7,-9]; + const array = [3.5,-5,7,-9]; const currentOutput = findMax(array); const targetOutput = 7; expect(currentOutput).toEqual(targetOutput); @@ -47,7 +47,7 @@ test("given an array with both positive and negative numbers, returns -the large // When passed to the max function // Then it should return the closest one to zero test("given an array with just negative numbers, return the closest one to 0",()=>{ - const array=[-5,-1,-7,-3] + const array=[-5,-1,-7.6,-3] const currentOutput=findMax(array) const targetOutput=-1 expect(currentOutput).toEqual(targetOutput) @@ -56,11 +56,18 @@ test("given an array with just negative numbers, return the closest one to 0",() // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number +test("given an array with decimal numbers, return the largest decimal",()=>{ + const array = [-5.9, -1.8, -7.6, -3.2]; + const currentOutput = findMax(array); + const targetOutput = -1.8; + expect(currentOutput).toEqual(targetOutput); +}) // Given an array with non-number values // When passed to the max function // Then it should return the max and ignore non-numeric values + // 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 From 3db5d07f400e6f5f8fa04c3c96e211fa85a8829f Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 10:01:39 +0000 Subject: [PATCH 08/20] Fix findMax function to return -Infinity for empty arrays and update tests for non-number values --- Sprint-1/implement/max.js | 16 +++++++--------- Sprint-1/implement/max.test.js | 9 +++++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 0c4fb9707..b106233ae 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,16 +1,14 @@ function findMax(elements) { - if (elements.length === 0) { - return Infinity; - } - if (elements.length === 1) { - return elements[0]; - } - const sortedElements = elements.sort((a, b) => a - b); - return sortedElements.reduce((a,b)=>Math.max(a,b)) +const filteredElements=elements.filter(x=>typeof x==="number") + + + const sortedElements = filteredElements.sort((a, b) => a - b); + + return sortedElements.reduce((a,b)=>Math.max(a,b),-Infinity) } -console.log(findMax([-5, -1, -7, -3])); +console.log(findMax([])); module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 7ea66f293..6cf14fdda 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -19,7 +19,7 @@ const findMax = require("./max.js"); test("given an empty array, returns -Infinity",()=>{ const array=[] const currentOutput=findMax(array) - const targetOutput=Infinity + const targetOutput=-Infinity expect(currentOutput).toEqual(targetOutput) }); @@ -66,7 +66,12 @@ test("given an array with decimal numbers, return the largest decimal",()=>{ // 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("given an array with non-number values, returns the max number",()=>{ + const array = [-5, -1,"k", -7.6,null, -3]; + const currentOutput = findMax(array); + const targetOutput = -1; + expect(currentOutput).toEqual(targetOutput); +}) // Given an array with only non-number values // When passed to the max function From b0a85a70f1d491224608d65494609d61d18098fb Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 10:08:44 +0000 Subject: [PATCH 09/20] Update findMax function to filter out NaN values and add test for non-number arrays --- Sprint-1/implement/max.js | 2 +- Sprint-1/implement/max.test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index b106233ae..a791a3b1b 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,7 +1,7 @@ function findMax(elements) { -const filteredElements=elements.filter(x=>typeof x==="number") +const filteredElements=elements.filter(x=>typeof x==="number" && !Number.isNaN(x)) const sortedElements = filteredElements.sort((a, b) => a - b); diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 6cf14fdda..e63775301 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -76,3 +76,9 @@ test("given an array with non-number values, returns the max number",()=>{ // 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("given an array with only non-numbers, returns -Infinity",()=>{ + const array = [false, "k", "-7.6", null,{},NaN]; + const currentOutput = findMax(array); + const targetOutput = -Infinity; + expect(currentOutput).toEqual(targetOutput); +}) From e2abc3fb21c0007d4edd590dac1ab2125d7a212d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 10:09:39 +0000 Subject: [PATCH 10/20] Refactor findMax function and tests for improved readability and consistency --- Sprint-1/implement/max.js | 11 ++---- Sprint-1/implement/max.test.js | 72 +++++++++++++++++----------------- 2 files changed, 40 insertions(+), 43 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index a791a3b1b..7dd598e64 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,14 +1,11 @@ function findMax(elements) { - - -const filteredElements=elements.filter(x=>typeof x==="number" && !Number.isNaN(x)) - + const filteredElements = elements.filter( + (x) => typeof x === "number" && !Number.isNaN(x) + ); const sortedElements = filteredElements.sort((a, b) => a - b); - return sortedElements.reduce((a,b)=>Math.max(a,b),-Infinity) + return sortedElements.reduce((a, b) => Math.max(a, b), -Infinity); } -console.log(findMax([])); - module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index e63775301..eb3b3e074 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -12,15 +12,15 @@ We have set things up already so that this file can see your function from the o const findMax = require("./max.js"); -// Given an empty array +// 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("given an empty array, returns -Infinity",()=>{ - const array=[] - const currentOutput=findMax(array) - const targetOutput=-Infinity - expect(currentOutput).toEqual(targetOutput) +test("given an empty array, returns -Infinity", () => { + const array = []; + const currentOutput = findMax(array); + const targetOutput = -Infinity; + expect(currentOutput).toEqual(targetOutput); }); // Given an array with one number @@ -36,49 +36,49 @@ test("given an array with one number, returns -that 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("given an array with both positive and negative numbers, returns -the largest number overall ",()=>{ - const array = [3.5,-5,7,-9]; - const currentOutput = findMax(array); - const targetOutput = 7; - expect(currentOutput).toEqual(targetOutput); -}) +test("given an array with both positive and negative numbers, returns -the largest number overall ", () => { + const array = [3.5, -5, 7, -9]; + const currentOutput = findMax(array); + const targetOutput = 7; + expect(currentOutput).toEqual(targetOutput); +}); // Given an array with just negative numbers // When passed to the max function // Then it should return the closest one to zero -test("given an array with just negative numbers, return the closest one to 0",()=>{ - const array=[-5,-1,-7.6,-3] - const currentOutput=findMax(array) - const targetOutput=-1 - expect(currentOutput).toEqual(targetOutput) -}) +test("given an array with just negative numbers, return the closest one to 0", () => { + const array = [-5, -1, -7.6, -3]; + const currentOutput = findMax(array); + const targetOutput = -1; + expect(currentOutput).toEqual(targetOutput); +}); // Given an array with decimal numbers // When passed to the max function // Then it should return the largest decimal number -test("given an array with decimal numbers, return the largest decimal",()=>{ - const array = [-5.9, -1.8, -7.6, -3.2]; - const currentOutput = findMax(array); - const targetOutput = -1.8; - expect(currentOutput).toEqual(targetOutput); -}) +test("given an array with decimal numbers, return the largest decimal", () => { + const array = [-5.9, -1.8, -7.6, -3.2]; + const currentOutput = findMax(array); + const targetOutput = -1.8; + expect(currentOutput).toEqual(targetOutput); +}); // 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("given an array with non-number values, returns the max number",()=>{ - const array = [-5, -1,"k", -7.6,null, -3]; - const currentOutput = findMax(array); - const targetOutput = -1; - expect(currentOutput).toEqual(targetOutput); -}) +test("given an array with non-number values, returns the max number", () => { + const array = [-5, -1, "k", -7.6, null, -3]; + const currentOutput = findMax(array); + const targetOutput = -1; + expect(currentOutput).toEqual(targetOutput); +}); // 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("given an array with only non-numbers, returns -Infinity",()=>{ - const array = [false, "k", "-7.6", null,{},NaN]; - const currentOutput = findMax(array); - const targetOutput = -Infinity; - expect(currentOutput).toEqual(targetOutput); -}) +test("given an array with only non-numbers, returns -Infinity", () => { + const array = [false, "k", "-7.6", null, {}, NaN]; + const currentOutput = findMax(array); + const targetOutput = -Infinity; + expect(currentOutput).toEqual(targetOutput); +}); From 573a32501c266c345313722ac906eb3089f18c21 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:09:31 +0000 Subject: [PATCH 11/20] Implement sum function and tests to handle various input scenarios, including empty arrays, negative numbers, decimals, and non-number values --- Sprint-1/implement/sum.js | 9 ++++++++ Sprint-1/implement/sum.test.js | 39 ++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..738b3991b 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,13 @@ function sum(elements) { + const filteredElements = elements.filter( + (x) => typeof x === "number" && !Number.isNaN(x) + ); + + if (filteredElements.length === 0) { + return 0; + } + return filteredElements.reduce((a, b) => a + b); } +console.log(sum([0])); module.exports = sum; diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index dd0a090ca..3f4584553 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -3,7 +3,7 @@ In this kata, you will need to implement a function that sums the numerical elements of an array E.g. sum([10, 20, 30]), target output: 60 -E.g. sum(['hey', 10, 'hi', 60, 10]), target output: 80 (ignore any non-numerical elements) +E.g. sum(['hey', 10, 'hi', 60, 10]), target output: 80 (ignore any non-numerical elements) */ const sum = require("./sum.js"); @@ -13,24 +13,59 @@ 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("given an empty array, returns 0", () => { + const array = []; + const currentOutput = sum(array); + const targetOutput = 0; + expect(currentOutput).toEqual(targetOutput); +}); // Given an array with just one number // When passed to the sum function // Then it should return that number +test("given an array with just one number, return the number", () => { + const array = [5]; + const currentOutput = sum(array); + const targetOutput = 5; + expect(currentOutput).toEqual(targetOutput); +}); // Given an array containing negative numbers // When passed to the sum function // Then it should still return the correct total sum +test("given an array containig negative numbers, return the total of the numbers", () => { + const array = [-5, -9, -3]; + const currentOutput = sum(array); + const targetOutput = -17; + expect(currentOutput).toEqual(targetOutput); +}); // Given an array with decimal/float numbers // When passed to the sum function // Then it should return the correct total sum +test("given an array containig decimalnumbers, return the total of the numbers", () => { + const array = [-5.5, 9, -3]; + const currentOutput = sum(array); + const targetOutput = 0.5; + expect(currentOutput).toEqual(targetOutput); +}); // Given an array containing non-number values // When passed to the sum function // Then it should ignore the non-numerical values and return the sum of the numerical elements +test("given an array containig non-number values,ignore the non-numerical values and return the total of the numbers", () => { + const array = [5, "s", null, NaN, -9, -3]; + const currentOutput = sum(array); + const targetOutput = -7; + expect(currentOutput).toEqual(targetOutput); +}); // Given an array with only non-number values // When passed to the sum function // Then it should return the least surprising value given how it behaves for all other inputs +test("given an array containig only non-number values, return 0", () => { + const array = ["s", null, NaN, "-3", true]; + const currentOutput = sum(array); + const targetOutput = 0; + expect(currentOutput).toEqual(targetOutput); +}); From a5a261ef363640ba99c854570023fb30a21e5a1d Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:12:06 +0000 Subject: [PATCH 12/20] added export module --- 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..4ed64b865 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,4 @@ -function dedupe() {} +function dedupe() { + +} +module.exports=dedupe \ No newline at end of file From d0a50ce4c63af8d96a58e57225e68b72de32ddbc Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:16:13 +0000 Subject: [PATCH 13/20] added parameter to dedupe --- Sprint-1/implement/dedupe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 4ed64b865..67f3c49e2 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,4 +1,4 @@ -function dedupe() { +function dedupe(arr) { } module.exports=dedupe \ No newline at end of file From 67699520df93ca9c2a2b502a4b49cd895376220b Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:16:26 +0000 Subject: [PATCH 14/20] Add test case for dedupe function to handle empty array --- Sprint-1/implement/dedupe.test.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index 23e0f8638..dae1b4e1d 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -3,7 +3,7 @@ const dedupe = require("./dedupe.js"); Dedupe Array 📖 Dedupe means **deduplicate** - + In this kata, you will need to deduplicate the elements of an array E.g. dedupe(['a','a','a','b','b','c']) target output: ['a','b','c'] @@ -16,7 +16,12 @@ E.g. dedupe([1, 2, 1]) target output: [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("given an empty array, it returns an empty array",()=>{ + const array=[] + const currentOutput=dedupe(array) + const targetOutput=[] + expect(currentOutput).toEqual(targetOutput) +}); // Given an array with no duplicates // When passed to the dedupe function From c10a14fbc408e402763a39563e4b39e9422f4035 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:17:05 +0000 Subject: [PATCH 15/20] Add early return for empty array in dedupe function --- Sprint-1/implement/dedupe.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 67f3c49e2..c4f215de7 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,4 +1,6 @@ function dedupe(arr) { - +if(arr.length===0){ + return [] +} } module.exports=dedupe \ No newline at end of file From efbcbb51093d8bbec9f206bead6e33fee3c2d571 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:21:44 +0000 Subject: [PATCH 16/20] Add dedupe function logic and test case for arrays without duplicates --- Sprint-1/implement/dedupe.js | 5 +++++ Sprint-1/implement/dedupe.test.js | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index c4f215de7..42e0e58f0 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -2,5 +2,10 @@ function dedupe(arr) { if(arr.length===0){ return [] } +for(let index in arr){ + if(arr[index]!==arr[index+1]){ + return arr + } +} } module.exports=dedupe \ No newline at end of file diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index dae1b4e1d..b08e4c795 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -26,6 +26,12 @@ test("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("given an array with no duplicates, it returns a copy of the original array", () => { + const array = [1,"d",6]; + const currentOutput = dedupe(array); + const targetOutput = [1,"d",6]; + expect(currentOutput).toEqual(targetOutput); +}); // Given an array with strings or numbers // When passed to the dedupe function From d5e51424c68a78657a2b443ef6c1624b6c6754d9 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:39:13 +0000 Subject: [PATCH 17/20] Refactor dedupe function and add test case for handling duplicates in arrays with mixed types --- Sprint-1/implement/dedupe.js | 23 +++++++++++++++-------- Sprint-1/implement/dedupe.test.js | 6 ++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 42e0e58f0..482aa5b4a 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1,11 +1,18 @@ function dedupe(arr) { -if(arr.length===0){ - return [] -} -for(let index in arr){ - if(arr[index]!==arr[index+1]){ - return arr + if (arr.length === 0) { + return []; + } + + for (let element of arr) { + if (arr.indexOf(element) === arr.lastIndexOf(element)) { + return arr; + } else { + arr.splice(arr.lastIndexOf(element), 1); } + } + return arr; } -} -module.exports=dedupe \ No newline at end of file + +console.log(dedupe([1, "d", 6, 1, 5, "d", null])); + +module.exports = dedupe; diff --git a/Sprint-1/implement/dedupe.test.js b/Sprint-1/implement/dedupe.test.js index b08e4c795..5848bf0a8 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -36,3 +36,9 @@ test("given an array with no duplicates, it returns a copy of the original arra // 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 +test("given an array with strings or numbers, it removes the duplicate values, preserving the first occurence of each element", () => { + const array = [1, "d", 6,1,5,"d",null]; + const currentOutput = dedupe(array); + const targetOutput = [1, "d", 6,5,null]; + expect(currentOutput).toEqual(targetOutput); +}); \ No newline at end of file From 498fa5f77fcca4cda0ebaade39bb58da4dd751b2 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:43:08 +0000 Subject: [PATCH 18/20] Refactor includes function to use for...of loop for improved readability --- Sprint-1/refactor/includes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..18af57496 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,8 +1,8 @@ -// Refactor the implementation of includes to use a for...of loop +// 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]; + for (let element of list) { + if (element === target) { return true; } From a8bb9811bb94876a61ecb4da6748dd0491f5dfc8 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:43:25 +0000 Subject: [PATCH 19/20] Refactor includes function to remove unnecessary whitespace for cleaner code --- Sprint-1/refactor/includes.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 18af57496..994131c59 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,8 +1,7 @@ -// Refactor the implementation of includes to use a for...of loop +// Refactor the implementation of includes to use a for...of loop function includes(list, target) { for (let element of list) { - if (element === target) { return true; } From 30584f678439b1f8b37fba1ee590aaf8973ca574 Mon Sep 17 00:00:00 2001 From: alexandru-pocovnicu <109530683+alexandru-pocovnicu@users.noreply.github.com> Date: Tue, 24 Feb 2026 12:15:34 +0000 Subject: [PATCH 20/20] Add solution function to calculate the sum of an array of numbers --- Sprint-1/stretch/aoc-2018-day1/solution.js | 985 +++++++++++++++++++++ 1 file changed, 985 insertions(+) diff --git a/Sprint-1/stretch/aoc-2018-day1/solution.js b/Sprint-1/stretch/aoc-2018-day1/solution.js index e69de29bb..212c43652 100644 --- a/Sprint-1/stretch/aoc-2018-day1/solution.js +++ b/Sprint-1/stretch/aoc-2018-day1/solution.js @@ -0,0 +1,985 @@ + +const data = ` ++10 +-9 ++12 ++5 ++13 +-6 +-19 +-4 +-17 +-1 ++7 ++18 +-13 +-15 +-6 +-11 +-12 +-9 ++12 ++2 ++14 ++11 ++17 +-10 +-21 ++6 ++18 +-4 +-16 ++15 ++8 ++13 ++12 ++4 +-1 +-19 +-7 ++14 ++8 +-3 ++5 +-9 ++16 +-11 ++21 +-3 ++23 +-8 +-16 ++11 +-3 ++1 ++16 +-3 ++14 +-9 ++17 ++5 +-3 ++17 ++12 ++19 +-12 +-14 ++13 +-3 ++6 ++15 ++18 +-8 ++14 ++14 ++3 ++18 ++4 +-9 ++12 ++6 ++8 ++18 ++12 ++13 +-6 +-13 +-13 +-17 ++14 +-3 ++2 ++12 +-6 ++16 +-9 ++6 +-1 +-4 ++17 ++9 ++6 +-3 ++9 +-15 +-11 +-17 ++7 +-9 +-18 +-21 ++2 +-11 ++12 +-21 +-8 ++14 ++5 ++17 +-4 ++8 ++4 ++9 ++7 +-5 +-7 ++6 ++19 ++20 ++22 ++8 +-11 ++17 +-1 +-1 ++14 ++11 +-9 +-18 ++19 +-10 ++5 +-17 +-19 +-4 ++3 ++7 ++5 ++5 ++21 ++17 ++17 +-12 ++13 ++15 ++18 ++17 +-4 +-7 +-15 ++1 ++5 +-16 +-9 +-11 +-5 ++7 +-10 +-15 ++3 ++11 +-6 +-9 ++10 ++17 ++15 ++7 ++13 ++15 +-6 ++10 ++7 ++12 +-4 +-12 ++3 ++7 +-15 +-13 ++16 ++1 +-9 +-18 +-10 ++6 ++9 +-11 ++7 ++10 ++11 +-10 ++18 ++4 ++5 ++19 +-1 +-16 ++18 +-4 ++5 ++11 ++10 ++17 ++4 +-1 +-13 ++2 +-10 +-17 +-12 ++16 ++16 ++12 ++14 ++12 ++18 ++12 ++2 +-13 ++15 ++16 +-6 ++10 +-13 +-15 +-12 ++6 ++19 +-6 ++9 ++3 ++19 +-3 ++5 ++3 ++6 ++23 ++4 +-18 +-17 +-15 ++1 ++4 ++13 ++11 +-13 ++6 +-18 +-13 +-7 +-13 ++5 ++1 +-19 ++11 +-9 ++5 +-1 +-11 ++8 +-11 +-1 +-14 ++11 +-13 +-15 ++16 +-18 ++7 ++16 ++18 +-13 ++7 +-8 +-12 ++16 +-2 ++9 +-14 +-10 +-17 +-8 +-16 +-19 ++5 +-1 +-2 ++4 ++7 +-19 +-20 ++19 ++17 ++12 ++17 +-14 ++19 +-17 ++7 +-2 +-6 +-19 +-8 +-7 +-2 ++21 ++19 +-12 ++18 +-15 ++33 +-4 +-1 ++2 ++5 ++12 +-1 ++4 +-9 ++23 ++1 ++16 ++1 ++13 +-16 ++9 ++4 ++12 +-1 ++9 ++22 ++1 +-5 ++12 +-14 +-22 ++9 ++28 ++2 ++3 ++10 ++22 +-10 +-2 ++23 ++7 ++14 +-18 ++7 +-9 ++10 ++9 ++11 ++6 ++12 ++11 ++13 ++9 +-4 ++9 ++7 +-19 +-5 +-6 ++5 +-13 +-11 ++13 +-8 +-2 +-9 ++3 +-15 ++20 ++8 ++10 +-14 +-13 ++2 +-11 ++5 ++7 +-13 ++15 +-21 +-16 ++19 +-21 ++10 +-33 ++7 +-28 ++12 +-19 +-25 +-14 ++11 +-32 +-23 +-10 ++17 +-32 +-16 +-18 ++8 ++2 +-74 +-17 ++7 +-8 +-8 +-12 +-12 +-16 +-19 +-2 ++20 +-4 ++19 +-21 ++18 +-10 +-17 ++10 +-20 ++15 +-19 ++13 +-7 +-17 ++4 +-18 ++9 ++17 +-23 ++21 +-27 +-11 +-18 +-23 ++6 +-17 +-9 ++8 +-19 ++10 +-8 +-8 +-7 +-7 ++12 +-18 ++5 +-3 ++12 +-17 +-2 +-13 +-3 ++8 +-2 ++14 +-21 ++16 +-19 +-14 ++1 +-2 ++11 +-3 +-21 ++8 ++2 ++9 ++24 ++18 ++14 +-19 ++12 ++17 +-9 +-6 ++10 ++13 ++13 +-24 +-5 ++27 +-20 +-15 +-6 +-21 ++4 +-19 +-1 ++31 ++17 ++14 ++8 ++11 ++7 +-20 ++7 ++17 ++4 ++7 +-5 ++11 ++26 ++8 ++19 ++19 ++34 ++15 ++8 ++3 ++4 ++10 ++6 +-28 +-13 +-7 ++3 ++19 ++18 +-13 ++9 ++61 ++33 +-39 ++26 +-53 +-5 ++2 +-8 +-30 +-9 +-4 +-16 +-15 ++32 ++15 ++28 ++20 +-88 ++5 +-14 +-16 +-51 ++26 ++5 +-7 +-7 +-22 ++2 +-14 ++8 +-15 +-20 +-40 ++22 +-27 ++2 +-18 +-38 +-23 +-10 +-8 +-3 ++8 +-27 ++17 ++33 ++16 ++77 +-35 ++52 ++339 ++3 +-275 ++81 ++169 +-299 +-668 +-79803 +-11 ++13 +-7 ++14 ++4 +-14 +-12 +-17 +-18 +-4 ++19 ++19 ++2 +-6 +-18 ++9 ++18 +-16 ++17 +-13 +-8 ++3 ++9 ++7 ++15 +-4 ++18 ++10 ++17 +-1 +-17 +-4 ++9 +-2 +-8 +-3 ++16 +-2 +-12 +-15 +-13 +-17 +-15 +-5 +-4 ++2 +-17 +-18 ++4 ++10 +-15 ++17 +-11 +-14 +-17 +-3 +-13 +-9 +-5 +-13 ++6 +-2 +-12 +-16 +-7 ++18 +-16 ++9 ++8 +-11 +-18 ++8 +-2 ++5 +-12 ++2 ++1 +-13 +-13 +-18 +-8 +-6 +-5 +-10 ++17 +-11 +-12 +-10 +-10 +-9 ++4 ++4 ++7 ++19 ++3 +-7 ++13 +-5 +-11 +-13 +-12 +-17 +-6 ++5 +-12 ++14 ++13 +-19 ++15 ++6 +-4 +-19 +-3 +-7 +-4 +-5 ++14 +-7 +-19 ++18 ++2 +-15 ++19 +-18 +-3 +-12 ++5 +-2 +-4 +-14 ++12 +-1 +-14 ++6 ++10 +-12 +-13 +-15 ++10 +-12 +-3 ++4 ++14 ++13 ++18 +-11 ++4 +-3 +-17 ++14 +-20 ++10 ++11 ++4 +-1 ++13 +-5 ++17 ++4 +-3 +-15 ++21 ++19 +-6 +-18 +-13 +-20 +-7 +-15 +-4 ++6 +-7 +-17 ++4 +-18 +-11 +-5 ++19 ++9 ++7 +-15 ++3 ++2 ++8 +-4 ++12 +-9 +-17 +-18 ++10 ++2 +-15 ++4 ++1 +-15 +-16 ++15 ++5 +-18 ++4 +-16 ++3 +-15 +-18 +-17 +-16 +-2 ++11 +-3 ++9 ++7 ++4 +-16 ++4 +-1 +-18 +-21 +-2 +-4 ++1 ++4 +-19 +-12 +-6 ++2 ++1 +-5 +-4 +-7 +-6 +-19 ++6 +-11 ++2 ++4 ++1 ++16 +-4 +-15 ++12 ++10 ++24 ++13 ++14 +-8 +-7 ++21 +-12 ++15 ++17 +-13 ++19 +-5 +-4 ++14 ++10 +-18 ++9 ++22 +-19 ++9 ++8 ++7 ++19 ++13 ++9 +-5 +-6 +-4 +-3 +-1 ++5 ++10 ++6 ++7 ++7 ++8 +-18 ++12 ++4 ++18 ++1 ++9 +-8 ++18 +-14 ++9 +-2 +-2 ++15 ++12 +-11 ++19 ++8 ++3 +-7 ++3 +-13 +-15 +-18 +-16 +-20 +-17 ++14 +-4 ++15 +-14 ++15 ++13 ++10 +-11 +-7 +-27 +-5 +-13 +-10 +-15 +-12 +-18 ++17 ++18 ++5 +-2 ++6 +-13 +-8 ++20 +-17 ++16 +-3 ++2 ++11 +-24 ++9 ++9 ++3 +-1 +-1 ++16 +-12 ++16 ++18 +-9 ++6 ++14 ++18 +-4 +-21 ++16 ++45 ++13 +-17 ++11 ++10 ++7 ++33 ++7 ++13 +-12 +-11 ++18 ++1 ++18 ++18 ++4 +-7 ++15 +-6 ++11 +-18 ++16 +-5 ++12 +-4 +-2 ++20 ++6 +-2 +-15 +-14 ++81142`; +const nums = data.trim().split(/\s+/).map(Number); + +function solution(arr) { + let sum = 0; + for (let elem of arr) { + sum += elem; + } + return sum; +} +console.log(solution(nums)); \ No newline at end of file