Bowl of Jelly Beans

Bowl of Jelly Beans

How many red beans do you have?

Difficulty: medium

In this challenge, you are asked to analyze a bowl of jelly beans. Your analysis should include the frequency of each bean color and a method that will return the probability of picking a particular colored jelly bean. The BeanAnalysis type should look something like:

typescript
1type BeanAnalysis = {
2  red: number;    //number of red beans
3  green: number;  //number of green beans
4  blue: number;   //number of blue beans
5  probability: (color: string) => number
6}

Write a function that will create an analysis of a bowl of jelly beans.

analyeBeans(beans: BowlOfBeans) => BeanAnalysis

Hint: your BeanAnalysis should include all bean colors even if the bowl does not have every color!

Hint: your solution should make it easy to change the color of beans available

One Possible Answer


View in Playground

popularity
On Fire
posted
Jul. 23, 2024