Skip to content

Commit

Permalink
update tasks and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Octowl committed Nov 5, 2024
1 parent 0076ccc commit 676212e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions objectIteration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...
}
Expand Down
16 changes: 9 additions & 7 deletions objectIteration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
});
Expand Down

0 comments on commit 676212e

Please sign in to comment.