Create new cla codewars
Here is a new CodeWars kata:
Kata Name: "Fruitful Harvest"
Description: You are a farmer who has just harvested a bounty of fruits from your orchard. You have a list of fruits, each with its own quantity and a special "harvest bonus" value. The harvest bonus is a percentage of the total quantity of fruits that you can add to your total harvest.
Task: Write a function that takes a list of fruits as input, where each fruit is represented as an object with two properties: name
(a string) and quantity
(an integer). The function should return the total harvest bonus as an integer.
Example Input:
[
{ name: "Apple", quantity: 10 },
{ name: "Banana", quantity: 20 },
{ name: "Cherry", quantity: 30 }
]
Example Output: 15 (because the total harvest bonus is 10% of the total quantity of fruits, which is 60)
Rules:
- The harvest bonus is calculated as 10% of the total quantity of fruits.
- If the total quantity of fruits is 0, the harvest bonus is 0.
- The function should return the total harvest bonus as an integer.
Code:
function fruitfulHarvest(fruits) {
// Your code here
}
Test Cases:
fruits = [{ name: "Apple", quantity: 10 }, { name: "Banana", quantity: 20 }];
should return 6fruits = [{ name: "Cherry", quantity: 30 }];
should return 3fruits = [];
should return 0fruits = [{ name: "Apple", quantity: 100 }, { name: "Banana", quantity: 200 }];
should return 30
Rank: 6 kyu
Tags: arrays, math, object-manipulation
I hope you enjoy this new kata!