From 676212e245f0dc6882e7093db0f223111142d6f0 Mon Sep 17 00:00:00 2001 From: Octowl Date: Tue, 5 Nov 2024 08:52:20 +0300 Subject: [PATCH] update tasks and tests --- objectIteration.js | 12 ++++++------ objectIteration.test.js | 16 +++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/objectIteration.js b/objectIteration.js index d66645c..63d990b 100644 --- a/objectIteration.js +++ b/objectIteration.js @@ -31,25 +31,25 @@ const fruits = [ }, ]; -// 1) Using `getFruitColor` function that accepts a `fruit` object as an argument, and returns the color of that `fruit` object +// 1) Write a `getFruitColor` function that accepts a `fruit` object as an argument, and returns the color of that `fruit` object function getFruitColor(fruit) { // write your code here... } // console.log(getFruitColor(fruits[0])); // Outputs: Red -// 2) Using `isFruitTasteMatching` function that accepts a `fruit` object as an argument and a `taste` string, return true if the fruit's taste matches the provided description, otherwise returns false +// 2) Write a `isFruitTasteMatching` function that accepts a `fruit` object as an argument and a `taste` string, return true if the fruit's taste matches the provided description, otherwise returns false function isFruitTasteMatching(fruit, taste) { // write your code here... } // console.log(isFruitTasteMatching(fruits[2], "Citrusy")); // Outputs: true -// 3) Using `addFruit` function that accepts an array of fruit object `fruits` and a `fruit` object (with id, name, color, and taste), it will add the new fruit to the end of the array, then returns the updated array -function addFruit(fruits, fruit) { +// 3) Write a `addFruit` function that accepts an array of fruit object `fruits` and the properties of a fruit (id, name, color, taste), it will add the new fruit to the end of the array, then returns the updated array +function addFruit(fruits, id, name, color, taste) { // write your code here... } -// console.log(addFruit(fruits, { id: 506, name: "Mango", color: "Yellow", taste: "Sweet" })); +// console.log(addFruit(fruits, 506, "Mango", "Yellow", "Sweet" )); -// Using `countSweetFruits`function that accepts an array of fruit objects `fruits`, and return the number of fruits with a sweet taste +// 4) Write a `countSweetFruits`function that accepts an array of fruit objects `fruits`, and return the number of fruits with a sweet taste function countSweetFruits(fruits) { // write your code here... } diff --git a/objectIteration.test.js b/objectIteration.test.js index 752898b..4b6d04d 100644 --- a/objectIteration.test.js +++ b/objectIteration.test.js @@ -66,7 +66,8 @@ describe("Fruit Data Functions", () => { color: "Yellow", taste: "Sweet", }; - const updatedFruits = addFruit([...fruits], newFruit); + const { id, name, color, taste } = newFruit(); + const updatedFruits = addFruit([...fruits], id, name, color, taste); expect(updatedFruits).toContainEqual(newFruit); expect(updatedFruits.length).toBe(fruits.length + 1); expect(updatedFruits[updatedFruits.length - 1]).toEqual(newFruit); @@ -76,12 +77,13 @@ describe("Fruit Data Functions", () => { describe("countSweetFruits", () => { it("should count the number of fruits with a sweet taste", () => { expect(countSweetFruits(fruits)).toBe(3); - const addedFruits = addFruit([...fruits], { - id: 506, - name: "Mango", - color: "Yellow", - taste: "Sweet", - }); + const addedFruits = addFruit( + [...fruits], + 506, + "Mango", + "Yellow", + "Sweet" + ); expect(countSweetFruits(addedFruits)).toBe(4); }); });