From 4938239b3a26710b68ae0d3615aa4ca16d5b2c63 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Tue, 28 Oct 2025 22:46:02 +0000 Subject: [PATCH 1/9] Max Excercise --- Sprint-1/implement/max.js | 7 +++++- Sprint-1/implement/max.test.js | 39 +++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/max.js b/Sprint-1/implement/max.js index 6dd76378e..5352e6a63 100644 --- a/Sprint-1/implement/max.js +++ b/Sprint-1/implement/max.js @@ -1,4 +1,9 @@ -function findMax(elements) { +function findMax(numbersList) { + let onlyNumbers = numbersList.filter((item) => typeof item === "number"); + let currentMax = Math.max(...onlyNumbers); ; + return currentMax; } +console.log(findMax([1, "apple", 5, 0, "banana", 3])); + module.exports = findMax; diff --git a/Sprint-1/implement/max.test.js b/Sprint-1/implement/max.test.js index 82f18fd88..ec0dcd921 100644 --- a/Sprint-1/implement/max.test.js +++ b/Sprint-1/implement/max.test.js @@ -16,28 +16,65 @@ 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"); +// This one is good to go! +test("given an empty array, returns -Infinity",() => { + const input = []; + const result = findMax(input); + expect(result).toEqual(-Infinity); +}); // Given an array with one number // When passed to the max function // Then it should return that number +test("given an array with 1 number, it returns the number ",() => {; + const inputMax1 = [3]; + const result = findMax(inputMax1); +expect(result).toEqual(3); +}); + // Given an array with both positive and negative numbers // When passed to the max function // Then it should return the largest number overall +test("give 2 positive numbers return the largest nunber",() => { + const inputMax2= [5,8]; + const result = findMax(inputMax2); + expect(result).toEqual(8); +}); // 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 colest to Zero",() =>{ +const inputMax3= [-5,-3]; +const result = findMax(inputMax3); +expect (result).toEqual(-3); +}); // 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, should return the largest decimal number",() => { +const inputMax4= [2.4,3.5]; +const result= findMax(inputMax4); +expect(result).toEqual(3.5); +}); // 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,it should return the max and ignore non-numeric values ",() => { +const inputMax5 = [2, "apple", 5, "banana", 8, "watermelon"]; +const result= findMax(inputMax5); +expect(result).toEqual(8); +}); // 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-number values,it should return the least surprising value given how it behaves for all other inputs ", () => { + const inputMax6= [ "computer", "bike", "car", "ball"]; +const result= findMax(inputMax6); +expect(result).toEqual(-Infinity); +}); + From 0d9e98c2a19849a4d8b0e128e2936ac4d317520d Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sun, 2 Nov 2025 19:20:39 +0000 Subject: [PATCH 2/9] Sum Excercise --- Sprint-1/implement/sum.js | 22 +++++++++++++++++++++- Sprint-1/implement/sum.test.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/sum.js b/Sprint-1/implement/sum.js index 9062aafe3..2b7fe9ed9 100644 --- a/Sprint-1/implement/sum.js +++ b/Sprint-1/implement/sum.js @@ -1,4 +1,24 @@ -function sum(elements) { +function sum(theArray) { + + let onyNumbers = theArray.filter(item => typeof item === 'number'); + + + const theFinalSum = onyNumbers.reduce((runningTotal, currentNumber) => { + return runningTotal + currentNumber; + }, 0); + + return theFinalSum; } +console.log (sum(["hey", 10, "hi", 60, 10])); + module.exports = sum; + +//numbersList.filter((item) => typeof item === "number"); +/* Sum the numbers in an array + +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) +*/ diff --git a/Sprint-1/implement/sum.test.js b/Sprint-1/implement/sum.test.js index dd0a090ca..34581e9dd 100644 --- a/Sprint-1/implement/sum.test.js +++ b/Sprint-1/implement/sum.test.js @@ -13,24 +13,55 @@ 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 inputNumber = []; + const result = sum(inputNumber); + expect(result).toEqual(0); +}); // Given an array with just one number // When passed to the sum function // Then it should return that number +test("given an array with 1 number, it returns the sam number", () => { + const inputNumber = [34]; + const result = sum(inputNumber); + expect(result).toEqual(34); +}); + // 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 containing negative numbers",() => { + const inputNegative = [10, -5, 20, -15]; + const result= sum(inputNegative ) + expect (result).toEqual(10); +}); + // 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 with decimal/float numbers", () => { + const inputFloat = [10.2, 10.3]; + const result = sum(inputFloat); + expect (result).toEqual(20.5); +}); // 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 containing non-number values", () => { + const inputNonNumbers = [1, "apple", 2, true, 3]; + const result = sum(inputNonNumbers); + expect (result).toEqual(6) +}); // 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 with only non-number values" , () =>{ + const nonNumbers = ["helo", "hi"]; + const result = sum(nonNumbers); + expect (result).toEqual(0) +}); \ No newline at end of file From b647f3ad83474503a160a72b1bdc8501870eff95 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sun, 2 Nov 2025 19:52:58 +0000 Subject: [PATCH 3/9] Dedupe Excercise --- Sprint-1/implement/dedupe.js | 14 +++++++++++++- Sprint-1/implement/dedupe.test.js | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Sprint-1/implement/dedupe.js b/Sprint-1/implement/dedupe.js index 781e8718a..4ac023955 100644 --- a/Sprint-1/implement/dedupe.js +++ b/Sprint-1/implement/dedupe.js @@ -1 +1,13 @@ -function dedupe() {} +function dedupe(arr) { + let result = []; + for (let item of arr) { + if (!result.includes(item)) { + result.push(item); + } + } + return result; +} + +console.log(dedupe(["a", "a", "a", "b", "b", "c"])); + +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 23e0f8638..4386d9f88 100644 --- a/Sprint-1/implement/dedupe.test.js +++ b/Sprint-1/implement/dedupe.test.js @@ -16,12 +16,26 @@ 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("dedupe an empty array returns an empty array", () =>{ + const inputEmpty = []; + const result = dedupe(inputEmpty); + expect(result).toEqual([]); +}); // 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", () => { + const inputNoDuplicates = ["a", "b", "c" ]; + const result = dedupe(inputNoDuplicates); + expect(result).toEqual(["a", "b", "c"]); +}); // 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 no duplicates", () => { + const inputMix = [1,1,2,2,3,3,4,4,5,5]; + const result = dedupe(inputMix); + expect(result).toEqual([1,2,3,4,5]); +}); \ No newline at end of file From 6cdb27566762b8a1fd0f7ab2e5b90fc38128700d Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sun, 2 Nov 2025 20:20:10 +0000 Subject: [PATCH 4/9] Includes Excercise --- Sprint-1/refactor/includes.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Sprint-1/refactor/includes.js b/Sprint-1/refactor/includes.js index 29dad81f0..9dba38900 100644 --- a/Sprint-1/refactor/includes.js +++ b/Sprint-1/refactor/includes.js @@ -1,13 +1,23 @@ // 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) { - return true; - } +// function includes(list, target) { +// for (let index = 0; index < list.length; index++) { +// const element = list[index]; +// if (element === target) { +// return true; +// } +// } +// return false; +// } + + +function includes(list,target){ + for (let value of list) { + if (value === target) { + return true; } - return false; } + return false; +}; module.exports = includes; From 8ad77a63b3a88928f24a803d9e35dbb7e5b40994 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sun, 2 Nov 2025 20:40:57 +0000 Subject: [PATCH 5/9] Ignore this Commit // It is not my solution I got help with AI. I confess I need to undestand more those 3 methodos to think how to get to this. // I will come back to it later. For now i will keep practicing more katas because they are help me. --- Sprint-1/fix/median.js | 45 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/Sprint-1/fix/median.js b/Sprint-1/fix/median.js index b22590bc6..ed65216c7 100644 --- a/Sprint-1/fix/median.js +++ b/Sprint-1/fix/median.js @@ -5,10 +5,49 @@ // Hint: Please consider scenarios when 'list' doesn't have numbers (the function is expected to return null) // or 'list' has mixed values (the function is expected to sort only numbers). +// function calculateMedian(list) { +// const middleIndex = Math.floor(list.length / 2); +// const median = list.splice(middleIndex, 1)[0]; +// return median; +// } + +// Ignore this Commit +// It is not my solution I got help with AI. I confess I need to undestand more those 3 methodos to think +//and get to this solution +// I will come back to it later. + function calculateMedian(list) { - const middleIndex = Math.floor(list.length / 2); - const median = list.splice(middleIndex, 1)[0]; - return median; + // non-array or empty inputs + if (!Array.isArray(list) || list.length === 0) { + return null; + } + + //Filter non-numeric values and create a new array of only numbers + + const numericList = list.filter( + (item) => typeof item === "number" && Number.isFinite(item) + ); + + // If after filtering, there are no numbers left, return null + if (numericList.length === 0) { + return null; + } + + //Sort the numeric list + const sortedList = [...numericList].sort((a, b) => a - b); + + const middleIndex = Math.floor(sortedList.length / 2); + + //Calculate the median based on list length (odd or even) + if (sortedList.length % 2 === 1) { + // Odd number of elements: return the middle element + return sortedList[middleIndex]; + } else { + // Even number of elements: return the average of the two middle elements + const mid1 = sortedList[middleIndex - 1]; + const mid2 = sortedList[middleIndex]; + return (mid1 + mid2) / 2; + } } module.exports = calculateMedian; From 95f9e07748f362bd1a1f34570d570df15d2a8899 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sun, 9 Nov 2025 15:40:39 +0000 Subject: [PATCH 6/9] Contains/ test / Excercise --- Sprint-2/implement/contains.js | 12 +++++++++++- Sprint-2/implement/contains.test.js | 25 ++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index cd779308a..5c6d5aab5 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,3 +1,13 @@ -function contains() {} +function contains(someObject, propertyName) { + let whatTheRobotFound = someObject[propertyName]; +if (someObject[propertyName] === undefined) { + return false; +} else { + return true; +}; +}; module.exports = contains; + +// Implement a function called contains that checks an object contains a +// particular property diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 326bdb1f2..5548527f5 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -20,16 +20,39 @@ as the object doesn't contains a key of 'c' // Given an empty object // When passed to contains // Then it should return false -test.todo("contains on empty object returns false"); +test("contains on empty object returns false",() =>{ + const inputEmpty = []; + const result = contains(inputEmpty); + expect(result).toEqual(false); +}); // Given an object with properties // When passed to contains with an existing property name // Then it should return true +test("Given an object with properties when pass to contains it returns true", () => { +const myObject = { + name: "Alice", + age: 30, + city: "London", +}; + const result = contains(myObject, "name"); + expect(result).toEqual(true); +}); // Given an object with properties // When passed to contains with a non-existent property name // Then it should return false +test("give a object with proprieties when pass contains with non-exist proprity name it should return false", () => { +const inputProprieties2 = ["f", "g", "h"]; +const result = contains(inputProprieties2); +expect (result).toEqual(false); +}); // Given invalid parameters like an array // When passed to contains // Then it should return false or throw an error +test("invalid parameters should return false or throw an error", () => { + const invalidParameters = ("f", "g", "h"); + const result = contains(invalidParameters); + expect(result).toEqual(false); +}); From 2ece854d5446e2f448b9fc795c3506d3b1fc2ad1 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sun, 9 Nov 2025 16:09:03 +0000 Subject: [PATCH 7/9] Deletes additions excercises from other branch --- Sprint-2/implement/contains.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 5c6d5aab5..105f56022 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -1,11 +1,11 @@ function contains(someObject, propertyName) { - let whatTheRobotFound = someObject[propertyName]; -if (someObject[propertyName] === undefined) { - return false; -} else { - return true; -}; -}; + let whatTheRobotFound = someObject[propertyName]; + if (someObject[propertyName] === undefined) { + return false; + } else { + return true; + } +} module.exports = contains; From 9285ca48c953c0959e9d5cac8f9b6c1a0523e817 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sun, 9 Nov 2025 16:25:26 +0000 Subject: [PATCH 8/9] New/ Contains Excercise --- Sprint-2/implement/contains.js | 2 -- Sprint-2/implement/contains.test.js | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Sprint-2/implement/contains.js b/Sprint-2/implement/contains.js index 105f56022..9cb455bb8 100644 --- a/Sprint-2/implement/contains.js +++ b/Sprint-2/implement/contains.js @@ -9,5 +9,3 @@ function contains(someObject, propertyName) { module.exports = contains; -// Implement a function called contains that checks an object contains a -// particular property diff --git a/Sprint-2/implement/contains.test.js b/Sprint-2/implement/contains.test.js index 5548527f5..e05d6dd0e 100644 --- a/Sprint-2/implement/contains.test.js +++ b/Sprint-2/implement/contains.test.js @@ -20,21 +20,21 @@ as the object doesn't contains a key of 'c' // Given an empty object // When passed to contains // Then it should return false -test("contains on empty object returns false",() =>{ - const inputEmpty = []; - const result = contains(inputEmpty); - expect(result).toEqual(false); +test("contains on empty object returns false", () => { + const inputEmpty = []; + const result = contains(inputEmpty); + expect(result).toEqual(false); }); // Given an object with properties // When passed to contains with an existing property name // Then it should return true test("Given an object with properties when pass to contains it returns true", () => { -const myObject = { - name: "Alice", - age: 30, - city: "London", -}; + const myObject = { + name: "Alice", + age: 30, + city: "London", + }; const result = contains(myObject, "name"); expect(result).toEqual(true); }); @@ -43,9 +43,9 @@ const myObject = { // When passed to contains with a non-existent property name // Then it should return false test("give a object with proprieties when pass contains with non-exist proprity name it should return false", () => { -const inputProprieties2 = ["f", "g", "h"]; -const result = contains(inputProprieties2); -expect (result).toEqual(false); + const inputProprieties2 = ["f", "g", "h"]; + const result = contains(inputProprieties2); + expect(result).toEqual(false); }); // Given invalid parameters like an array From 8e18b52b6ec88740190996aafabaf4941a9c532a Mon Sep 17 00:00:00 2001 From: Della Bella Date: Mon, 10 Nov 2025 08:47:55 +0000 Subject: [PATCH 9/9] Quote-Generator Excercise --- Sprint-3/quote-generator/index.html | 8 ++-- Sprint-3/quote-generator/quotes.js | 18 ++++++++- Sprint-3/quote-generator/style.css | 61 +++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/Sprint-3/quote-generator/index.html b/Sprint-3/quote-generator/index.html index 30b434bcf..bf43cf1ad 100644 --- a/Sprint-3/quote-generator/index.html +++ b/Sprint-3/quote-generator/index.html @@ -3,13 +3,15 @@ - Title here + + Quote Generator App -

hello there

+

- + + diff --git a/Sprint-3/quote-generator/quotes.js b/Sprint-3/quote-generator/quotes.js index 4a4d04b72..6b288cd8f 100644 --- a/Sprint-3/quote-generator/quotes.js +++ b/Sprint-3/quote-generator/quotes.js @@ -15,11 +15,19 @@ // --------------- // pickFromArray(['a','b','c','d']) // maybe returns 'c' +let quoteDisplay = document.getElementById("quote"); +let authorDisplay = document.getElementById("author"); +let newQuoteButton = document.getElementById("new-quote"); + + // You don't need to change this function function pickFromArray(choices) { return choices[Math.floor(Math.random() * choices.length)]; } + + + // A list of quotes you can use in your app. // DO NOT modify this array, otherwise the tests may break! const quotes = [ @@ -490,4 +498,12 @@ const quotes = [ }, ]; -// call pickFromArray with the quotes array to check you get a random quote +function displayNewQuote() { + const randomQuoteObject = pickFromArray(quotes); + quoteDisplay.innerHTML = ' " ' + randomQuoteObject.quote; + authorDisplay.innerHTML = ' - ' + randomQuoteObject.author; +} + +newQuoteButton.addEventListener("click", displayNewQuote); + +displayNewQuote();//disply quote when open the page \ No newline at end of file diff --git a/Sprint-3/quote-generator/style.css b/Sprint-3/quote-generator/style.css index 63cedf2d2..a0bec58fd 100644 --- a/Sprint-3/quote-generator/style.css +++ b/Sprint-3/quote-generator/style.css @@ -1 +1,62 @@ /** Write your CSS in here **/ + +body { + font-family: 'Times New Roman',Times, serif; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + min-height: 100vh; + margin: 0; + background-color: #fcf1ea; + color: #333; + padding: 20px; + box-sizing: border-box; +} + +h1 { + color: #2c3e50; + margin-bottom: 30px; + font-size: 2.5em; + text-align: center; +} + +#quote { + font-size: 1.8em; + font-style: italic; + text-align: center; + max-width: 800px; + margin-bottom: 15px; + line-height: 1.5; + color: #555; +} + +#author { + font-size: 1.1em; + font-weight: bold; + text-align: center; + margin-bottom: 40px; + color: #777; +} + +#new-quote { + background-color: #eb9428; + color: white; + border: none; + padding: 15px 30px; + font-size: 1.1em; + border-radius: 8px; + cursor: pointer; + transition: background-color 0.3s ease, transform 0.2s ease; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); +} + +#new-quote:hover { + background-color: #473408; + transform: translateY(-2px); +} + +#new-quote:active { + background-color: #2c3e50; + transform: translateY(0); +} \ No newline at end of file