From 750f0f279e3dc83c951317377a66a2ea68aec3ba Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Tue, 14 Jan 2025 21:29:49 +0000 Subject: [PATCH 01/11] solution1.js - created cowsay program --- challenges/challenge-cowsay-two/solution1.js | 41 ++++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/challenges/challenge-cowsay-two/solution1.js b/challenges/challenge-cowsay-two/solution1.js index a7f2416..f306754 100644 --- a/challenges/challenge-cowsay-two/solution1.js +++ b/challenges/challenge-cowsay-two/solution1.js @@ -1,30 +1,37 @@ // ================= -// Stripped down cowsayer CLI, -// no libraries -// https://nodejs.dev/learn/nodejs-accept-arguments-from-the-command-line +// Stripped down cowsayer CLI, no libraries // ================= // 1. Accept arguments - -// how will you accept arguments? +// Accept the argument from the command line +const args = process.argv.slice(2); // Skip node and script name +let saying = args[0] || "Moo!"; // Default saying if no argument is provided // 2. Make supplies for our speech bubble - let topLine = '_'; let bottomLine = '-'; -let saying = ''; // 3. Make a cow that takes a string - function cowsay(saying) { -// how will you make the speech bubble contain the text? - -// where will the cow picture go? - -// how will you account for the parameter being empty? - + // Create speech bubble + const speechBubble = ` + ${topLine.repeat(saying.length + 2)} +< ${saying} > + ${bottomLine.repeat(saying.length + 2)} +`; + + // Add ASCII cow to speech bubble + const cow = ` + \\ ^__^ + \\ (oo)\\_______ + (__)\\ )\\/\\ + ||----w | + || || +`; + + // Combine speech bubble and cow + return speechBubble + cow; } -//4. Pipe argument into cowsay function and return a cow - -// how will you log this to the console? +// 4. Pipe argument into cowsay function and return a cow +console.log(cowsay(saying)); From 8af65fa47365d531a0db605028bed71af03cfebc Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Tue, 14 Jan 2025 21:30:38 +0000 Subject: [PATCH 02/11] solution2.js - created cowsay program that reads input from user --- challenges/challenge-cowsay-two/solution2.js | 46 ++++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/challenges/challenge-cowsay-two/solution2.js b/challenges/challenge-cowsay-two/solution2.js index 8aca857..bb7a84e 100644 --- a/challenges/challenge-cowsay-two/solution2.js +++ b/challenges/challenge-cowsay-two/solution2.js @@ -1,18 +1,46 @@ // ================= -// Stripped down cowsayer CLI, -// no libraries or arguments -// https://nodejs.dev/learn/accept-input-from-the-command-line-in-nodejs +// Stripped down cowsayer CLI, no libraries or arguments // ================= -// 1. Make a command line interface. +// 1. Make a command line interface. +const readline = require('readline'); + +// Create readline interface +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); // 2. Make supplies for our speech bubble +let topLine = '_'; +let bottomLine = '-'; // 3. Make a cow that takes a string - const cow = (saying) => { - // how did you make the cow before? -} + // Create speech bubble + const speechBubble = ` + ${topLine.repeat(saying.length + 2)} +< ${saying} > + ${bottomLine.repeat(saying.length + 2)} +`; + + // Add ASCII cow to speech bubble + const cowArt = ` + \\ ^__^ + \\ (oo)\\_______ + (__)\\ )\\/\\ + ||----w | + || || +`; + + return speechBubble + cowArt; +}; -// 4. Use readline to get a string from the terminal -// (with a prompt so it's clearer what we want) \ No newline at end of file +// 4. Use readline to get a string from the terminal +// Prompt the user for input +rl.question("What do you want the cow to say? ", (input) => { + // If input is empty, provide a default message + const saying = input.trim() || "Moo!"; + console.log(cow(saying)); // Generate and print the cow with speech bubble + rl.close(); // Close the readline interface +}); From 2103bf3d7a7e3c0709ecf21313a7c7739828d4db Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Tue, 14 Jan 2025 22:15:25 +0000 Subject: [PATCH 03/11] created dog photo gallery --- challenges/dog-photo-gallery/index.html | 19 ++++++++ challenges/dog-photo-gallery/script.js | 32 +++++++++++++ challenges/dog-photo-gallery/styles.css | 62 +++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 challenges/dog-photo-gallery/index.html create mode 100644 challenges/dog-photo-gallery/script.js create mode 100644 challenges/dog-photo-gallery/styles.css diff --git a/challenges/dog-photo-gallery/index.html b/challenges/dog-photo-gallery/index.html new file mode 100644 index 0000000..19e5e25 --- /dev/null +++ b/challenges/dog-photo-gallery/index.html @@ -0,0 +1,19 @@ + + + + + + Random Dog Photo Gallery + + + + +

Random Dog Photo Gallery

+ + + + + + + + \ No newline at end of file diff --git a/challenges/dog-photo-gallery/script.js b/challenges/dog-photo-gallery/script.js new file mode 100644 index 0000000..b1e0933 --- /dev/null +++ b/challenges/dog-photo-gallery/script.js @@ -0,0 +1,32 @@ +document.addEventListener('DOMContentLoaded', () => { + const addImageBtn = document.getElementById('addImageBtn'); + const clearGalleryBtn = document.getElementById('clearGalleryBtn'); + const gallery = document.getElementById('gallery'); + + addImageBtn.addEventListener('click', fetchAndDisplayImage); + clearGalleryBtn.addEventListener('click', () => { + gallery.innerHTML = ''; + }); + + async function fetchAndDisplayImage() { + try { + const response = await fetch('https://dog.ceo/api/breeds/image/random'); + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + const data = await response.json(); + if (data.status !== 'success') { + throw new Error('Failed to fetch dog image.'); + } + const listItem = document.createElement('li'); + const image = document.createElement('img'); + image.src = data.message; + image.alt = 'Random Dog'; + listItem.appendChild(image); + gallery.appendChild(listItem); + } catch (error) { + console.error('Error fetching and displaying image:', error); + alert('Failed to load dog image. Please try again later.'); + } + } +}); diff --git a/challenges/dog-photo-gallery/styles.css b/challenges/dog-photo-gallery/styles.css new file mode 100644 index 0000000..c5beea5 --- /dev/null +++ b/challenges/dog-photo-gallery/styles.css @@ -0,0 +1,62 @@ +body { + font-family: Arial, sans-serif; + text-align: center; + margin: 20px; +} + +#gallery { + list-style-type: none; + padding: 0; +} + +#gallery li { + display: inline-block; + margin: 10px; +} + +#gallery img { + max-width: 200px; + border-radius: 8px; +} + +#addImageBtn { + padding: 10px 20px; + margin: 10px; + border: none; + background-color: #007BFF; + color: white; + font-size: 16px; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s, transform 0.2s; +} + +#addImageBtn:hover { + background-color: #0056b3; + transform: scale(1.05); +} + +#addImageBtn:focus { + outline: 2px solid #003f7f; +} + +#clearGalleryBtn { + padding: 10px 20px; + margin: 10px; + border: none; + background-color: #FF5733; + color: white; + font-size: 16px; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s, transform 0.2s; +} + +#clearGalleryBtn:hover { + background-color: #c44123; + transform: scale(1.05); +} + +#clearGalleryBtn:focus { + outline: 2px solid #922d17; +} \ No newline at end of file From 6c32ac6ebf9ef60cee03aadb252d1d7e60c4ad61 Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Wed, 15 Jan 2025 19:22:39 +0000 Subject: [PATCH 04/11] stringCalculator.js - created stringCalculator and jest test --- .../katas-tdd/calculator/stringCalculator.js | 21 +++++++++++ .../calculator/stringCalculator.test.js | 36 +++++++++++++++++++ challenges/unit-testing/package-lock.json | 6 ++-- 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 challenges/unit-testing/katas-tdd/calculator/stringCalculator.js create mode 100644 challenges/unit-testing/katas-tdd/calculator/stringCalculator.test.js diff --git a/challenges/unit-testing/katas-tdd/calculator/stringCalculator.js b/challenges/unit-testing/katas-tdd/calculator/stringCalculator.js new file mode 100644 index 0000000..5aba22b --- /dev/null +++ b/challenges/unit-testing/katas-tdd/calculator/stringCalculator.js @@ -0,0 +1,21 @@ +function add(numbers) { + // Step 1: Handle an empty string + if (numbers === "") return 0; + + // Step 2: Handle an unknown number of inputs + const numArray = numbers.split(",").map(Number); + + // Step 3: Ignore numbers greater than 1000 + const filteredNumbers = numArray.filter(num => num <= 1000); + + // Step 4: Handle negative numbers + const negatives = filteredNumbers.filter(num => num < 0); + if (negatives.length > 0) { + throw new Error(`negatives not allowed: ${negatives.join(", ")}`); + } + + // Sum up the valid numbers + return filteredNumbers.reduce((sum, num) => sum + num, 0); +} + +module.exports = add; \ No newline at end of file diff --git a/challenges/unit-testing/katas-tdd/calculator/stringCalculator.test.js b/challenges/unit-testing/katas-tdd/calculator/stringCalculator.test.js new file mode 100644 index 0000000..fb2d387 --- /dev/null +++ b/challenges/unit-testing/katas-tdd/calculator/stringCalculator.test.js @@ -0,0 +1,36 @@ +const add = require("./stringCalculator"); + +describe("String Calculator", () => { + // Step 1: Simplest case + test("should return 0 for an empty string", () => { + expect(add("")).toBe(0); + }); + + test("should return the number itself for a single number", () => { + expect(add("5")).toBe(5); + }); + + test("should return the sum of two numbers", () => { + expect(add("3,6")).toBe(9); + }); + + // Step 2: Handle an unknown amount of numbers + test("should handle an unknown amount of numbers", () => { + expect(add("1,2,3,4,5")).toBe(15); + }); + + // Step 3: Ignore big numbers + test("should ignore numbers greater than 1000", () => { + expect(add("2,1001")).toBe(2); + expect(add("1000,1001")).toBe(1000); + }); + + // Step 4: Negative numbers + test("should throw an error for a single negative number", () => { + expect(() => add("-1")).toThrow("negatives not allowed: -1"); + }); + + test("should throw an error for multiple negative numbers", () => { + expect(() => add("1,-4,-1")).toThrow("negatives not allowed: -4, -1"); + }); +}); diff --git a/challenges/unit-testing/package-lock.json b/challenges/unit-testing/package-lock.json index 55d5bc6..b733c4d 100644 --- a/challenges/unit-testing/package-lock.json +++ b/challenges/unit-testing/package-lock.json @@ -1578,9 +1578,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "license": "MIT", "dependencies": { From 64bab2f1abc01360fc07572f930ee019c2d98e59 Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Wed, 15 Jan 2025 21:28:18 +0000 Subject: [PATCH 05/11] verify.js - created password verify program and jest test --- .../katas-tdd/password-verifier/verify.js | 21 ++++++++++++ .../password-verifier/verify.test.js | 34 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 challenges/unit-testing/katas-tdd/password-verifier/verify.js create mode 100644 challenges/unit-testing/katas-tdd/password-verifier/verify.test.js diff --git a/challenges/unit-testing/katas-tdd/password-verifier/verify.js b/challenges/unit-testing/katas-tdd/password-verifier/verify.js new file mode 100644 index 0000000..dafc24d --- /dev/null +++ b/challenges/unit-testing/katas-tdd/password-verifier/verify.js @@ -0,0 +1,21 @@ +// Step 1: Check for null or too short passwords +function verify(password) { + if (!password || password.length < 8) { + return "Password rejected"; + } + + // Step 2: Check for at least one uppercase letter + if (!/[A-Z]/.test(password)) { + return "Password rejected"; + } + + // Step 3: Check for at least one numeric character + if (!/[0-9]/.test(password)) { + return "Password rejected"; + } + + // Step 4: If all conditions pass + return "Password accepted"; +} + +module.exports = verify; \ No newline at end of file diff --git a/challenges/unit-testing/katas-tdd/password-verifier/verify.test.js b/challenges/unit-testing/katas-tdd/password-verifier/verify.test.js new file mode 100644 index 0000000..ea2a990 --- /dev/null +++ b/challenges/unit-testing/katas-tdd/password-verifier/verify.test.js @@ -0,0 +1,34 @@ +const verify = require('./verify'); + +describe("Password Verifier", () => { + + // Step 1: Test password length + test("rejects passwords shorter than 8 characters", () => { + expect(verify("short")).toBe("Password rejected"); + }); + + // Step 2: Test null passwords + test("rejects null passwords", () => { + expect(verify(null)).toBe("Password rejected"); + }); + + // Step 3: Test passwords without uppercase letters + test("rejects passwords without uppercase letters", () => { + expect(verify("lowercase1")).toBe("Password rejected"); + }); + + // Step 3: Test passwords with uppercase letters + test("accepts passwords with uppercase letters and at least 8 characters", () => { + expect(verify("ValidPass1")).toBe("Password accepted"); + }); + + // Step 4: Test passwords without numbers + test("rejects passwords without numbers", () => { + expect(verify("NoNumbers")).toBe("Password rejected"); + }); + + // Step 4: Test passwords with all conditions met + test("accepts passwords with numbers and all other conditions met", () => { + expect(verify("Password1")).toBe("Password accepted"); + }); +}); \ No newline at end of file From 0a68597e4545739a8a12e037009eae263decc57f Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Wed, 15 Jan 2025 21:38:05 +0000 Subject: [PATCH 06/11] convert-to-new-roman.js and convert-to-old-roman.js - created programs with jest tests --- .../roman-numerals/convert-to-new-roman.js | 29 +++++++++++++++++-- .../convert-to-new-roman.test.js | 8 ++++- .../roman-numerals/convert-to-old-roman.js | 21 +++++++++++++- .../convert-to-old-roman.test.js | 6 ++++ 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-new-roman.js b/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-new-roman.js index 0f2fe4b..de088e0 100644 --- a/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-new-roman.js +++ b/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-new-roman.js @@ -1,3 +1,28 @@ -function convertToNewRoman(n) {} +function convertToNewRoman(n) { + const romanNumerals = [ + { value: 1000, numeral: 'M' }, + { value: 900, numeral: 'CM' }, + { value: 500, numeral: 'D' }, + { value: 400, numeral: 'CD' }, + { value: 100, numeral: 'C' }, + { value: 90, numeral: 'XC' }, + { value: 50, numeral: 'L' }, + { value: 40, numeral: 'XL' }, + { value: 10, numeral: 'X' }, + { value: 9, numeral: 'IX' }, + { value: 5, numeral: 'V' }, + { value: 4, numeral: 'IV' }, + { value: 1, numeral: 'I' } + ]; -module.exports = convertToNewRoman; + let result = ''; + for (const { value, numeral } of romanNumerals) { + while (n >= value) { + result += numeral; + n -= value; + } + } + return result; +} + +module.exports = convertToNewRoman; \ No newline at end of file diff --git a/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-new-roman.test.js b/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-new-roman.test.js index ae49f73..7011963 100644 --- a/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-new-roman.test.js +++ b/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-new-roman.test.js @@ -2,6 +2,12 @@ let convertToNewRoman = require("./convert-to-new-roman"); test("returns I if passed 1 as an argument", function () { // Arrange + const input = 1; + const expectedOutput = "I"; + // Act + const result = convertToNewRoman(input); + // Assert -}); + expect(result).toBe(expectedOutput); +}); \ No newline at end of file diff --git a/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-old-roman.js b/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-old-roman.js index f7f0d06..7473e9c 100644 --- a/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-old-roman.js +++ b/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-old-roman.js @@ -1,3 +1,22 @@ -function convertToOldRoman(n) {} +function convertToOldRoman(n) { + const romanNumerals = [ + { value: 1000, numeral: 'M' }, + { value: 500, numeral: 'D' }, + { value: 100, numeral: 'C' }, + { value: 50, numeral: 'L' }, + { value: 10, numeral: 'X' }, + { value: 5, numeral: 'V' }, + { value: 1, numeral: 'I' } + ]; + + let result = ''; + for (const { value, numeral } of romanNumerals) { + while (n >= value) { + result += numeral; + n -= value; + } + } + return result; +} module.exports = convertToOldRoman; diff --git a/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-old-roman.test.js b/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-old-roman.test.js index b9a4386..aa19357 100644 --- a/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-old-roman.test.js +++ b/challenges/unit-testing/katas-tdd/roman-numerals/convert-to-old-roman.test.js @@ -2,6 +2,12 @@ let convertToOldRoman = require("./convert-to-old-roman"); test("returns I if passed 1 as an argument", function () { // Arrange + const input = 1; + const expectedOutput = "I"; + // Act + const result = convertToOldRoman(input); + // Assert + expect(result).toBe(expectedOutput); }); From 9284c6b7b674e2ae459f62fa4c43957060364f88 Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Wed, 15 Jan 2025 21:41:44 +0000 Subject: [PATCH 07/11] car-sales.js - created car sales program --- .../unit-testing/passing-tests/car-sales/car-sales.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/challenges/unit-testing/passing-tests/car-sales/car-sales.js b/challenges/unit-testing/passing-tests/car-sales/car-sales.js index e8bb851..100bfa4 100644 --- a/challenges/unit-testing/passing-tests/car-sales/car-sales.js +++ b/challenges/unit-testing/passing-tests/car-sales/car-sales.js @@ -1,3 +1,8 @@ -function sales(carsSold) {} +function sales(carsSold) { + return carsSold.reduce((acc, car) => { + acc[car.make] = (acc[car.make] || 0) + car.price; + return acc; + }, {}); +} module.exports = sales; From 6e1558d43a098ca80da6f8aae0dbb0a3a762bffb Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Wed, 15 Jan 2025 21:43:54 +0000 Subject: [PATCH 08/11] factorial.js - created factorial program --- .../passing-tests/factorial/factorial.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/challenges/unit-testing/passing-tests/factorial/factorial.js b/challenges/unit-testing/passing-tests/factorial/factorial.js index fefa436..dd3603b 100644 --- a/challenges/unit-testing/passing-tests/factorial/factorial.js +++ b/challenges/unit-testing/passing-tests/factorial/factorial.js @@ -8,6 +8,20 @@ // calculate and return the factorial of int // note: factorial of 0 is 1 -function factorial(int) {} +function factorial(int) { + if (int < 0) { + throw new Error("Factorial is not defined for negative numbers"); + } + if (int === 0 || int === 1) { + return 1; + } -module.exports = factorial; + let result = 1; + for (let i = 2; i <= int; i++) { + result *= i; + } + + return result; +} + +module.exports = factorial; \ No newline at end of file From e4e692cb174448c84d0e85400b3e1a928455b5f6 Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Wed, 15 Jan 2025 21:46:56 +0000 Subject: [PATCH 09/11] get-average.js - created get-average program --- .../passing-tests/get-average/get-average.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/challenges/unit-testing/passing-tests/get-average/get-average.js b/challenges/unit-testing/passing-tests/get-average/get-average.js index b5588a5..93774f1 100644 --- a/challenges/unit-testing/passing-tests/get-average/get-average.js +++ b/challenges/unit-testing/passing-tests/get-average/get-average.js @@ -2,6 +2,13 @@ // return the average of all the numbers // be sure to exclude the strings -function average(numbers) {} +function average(numbers) { + let numericValues = numbers.filter(item => typeof item === "number"); + if (numericValues.length === 0) { + return 0; + } + let sum = numericValues.reduce((acc, num) => acc + num, 0); + return sum / numericValues.length; +} module.exports = average; From 88cb467a60df5db88a749b1e8481a889595aaad4 Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Wed, 15 Jan 2025 21:54:01 +0000 Subject: [PATCH 10/11] largest-number.test.js - created jest test --- .../largest-number/largest-number.test.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/challenges/unit-testing/writing-tests/largest-number/largest-number.test.js b/challenges/unit-testing/writing-tests/largest-number/largest-number.test.js index ce67420..fd42331 100644 --- a/challenges/unit-testing/writing-tests/largest-number/largest-number.test.js +++ b/challenges/unit-testing/writing-tests/largest-number/largest-number.test.js @@ -2,12 +2,13 @@ let getLargestNumber = require("./largest-number"); test("returns largest number in array", function () { // Arrange + const input = [3, 21, 88, 4, 36]; + const expected = 88; + // Act - // Assert -}); - -// example -// input: [3, 21, 88, 4, 36]; -// expected: 88; + const result = getLargestNumber(input); -// also test that the original array hasn't changed + // Assert + expect(result).toBe(expected); + expect(input).toEqual([3, 21, 88, 4, 36]); // Ensures the original array hasn't changed +}); \ No newline at end of file From 1c1754bf682aa9d29b961235f695bad208418306 Mon Sep 17 00:00:00 2001 From: rawrnoodles Date: Wed, 15 Jan 2025 22:16:53 +0000 Subject: [PATCH 11/11] remove-vowels-in-array.test.js - created jest test and answered question in remove-vowels.js --- .../remove-vowels-in-array.test.js | 17 ++++++++++------- .../remove-vowels/remove-vowels.js | 7 +++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.test.js b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.test.js index ee739e2..bd62f35 100644 --- a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.test.js +++ b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels-in-array.test.js @@ -1,11 +1,14 @@ let removeVowelsFromWords = require("./remove-vowels-in-array"); +// Test case for removing vowels from all words in an array test("remove vowels from all words in array", function () { - // Arrange - // Act - // Assert -}); + // Arrange: Define the input and expected output + const input = ["Irina", "Etza", "Daniel"]; + const expectedOutput = ["rn", "tz", "Dnl"]; -// example -// input: ["Irina", "Etza", "Daniel"] -// expected output: ["rn", "tz", "Dnl"] + // Act: Call the function with the input + const actualOutput = removeVowelsFromWords(input); + + // Assert: Verify that the actual output matches the expected output + expect(actualOutput).toEqual(expectedOutput); +}); \ No newline at end of file diff --git a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels.js b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels.js index e5bb67b..992dd7c 100644 --- a/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels.js +++ b/challenges/unit-testing/writing-tests/remove-vowels/remove-vowels.js @@ -26,4 +26,11 @@ module.exports = removeVowels; let result = removeVowels('samuel'); what is the value of result? + + - Split 'samuel' into characters: ['s', 'a', 'm', 'u', 'e', 'l'] + - Exclude vowels: ['s', 'm', 'l'] + - Join result: 'sml' + + The value of result is: 'sml' + */