Given a Pond (array of Fishes) where the Fish object is as below:
// Fish
{
name: string,
size: 'small'|'medium'|'large'
hungry: boolean
}
const pond = [
{ name: 'Nemo', size: 'small', hungry: true },
{ name: 'Dory', size: 'medium', hungry: false },
{ name: 'Bubbles', size: 'large', hungry: true },
{ name: 'Fin', size: 'medium', hungry: true },
{ name: 'Marlin', size: 'large', hungry: false },
{ name: 'Gill', size: 'small', hungry: true },
{ name: 'Bruce', size: 'medium', hungry: true },
{ name: 'Squirt', size: 'small', hungry: false },
{ name: 'Hank', size: 'large', hungry: true },
{ name: 'Bailey', size: 'medium', hungry: false }
];
Create a custom React hook "useFishing" which when called, creates a wave in Pond and do the following:
- Catch a random fish
- If the fish is not hungry, then the fish skips the hook and
returns []
. - If the fish is hungry, return the fish and all the fishes which are bigger in size to the caught fish and are hungry. (Analogy is the bigger hungry fishes try to catch this fellow and get trapped too)
returns Fish[]