When and how whiteboarding practice is implemented will be up to your teacher. Below is a recommended prompt.
For this section's whiteboarding lesson, we'll focus on using a given data structure and filtering collections of objects.
As the interviewee:
As the interviewer:
There are two prompts listed below for the same problem. Make sure to switch who's whiteboarding for each prompt. There are also further exploration prompts to optionally complete.
You're working on an app that presents user's with information about dinosaurs.
The Dinosaur
class has the following data structure:
name: string
period: string
diet: string
walksOnFourLegs: boolean
yearDiscovered: number
popularity: number
Example Data:
dino1 = {
name: Tyrannosaurus rex,
period: Mesozoic,
diet: carnivore,
walksOnFourLegs: false,
yearDiscovered: 1902,
popularity: 999
}
dino2 = {
name: Brachiosaurus,
period: Jurassic,
diet: herbivore,
walksOnFourLegs: true,
yearDiscovered: 1900,
popularity: 959
}
dino3 = {
name: Parasaurolophus,
period: Cretaceous,
diet: herbivore,
walksOnFourLegs: true,
yearDiscovered: 1922,
popularity: 500
}
dino4 = {
name: Stegosaurus,
period: Jurassic,
diet: herbivore,
walksOnFourLegs: true,
yearDiscovered: 1876,
popularity: 903
}
Prompt 1:
The client wants users to be able to search for dinosaurs by diet and period. Write a method that takes in three parameters: a value for the period, a value for the diet, and an array of dinosaur objects to filter.
Example:
"Jurassic", "herbivore", [ dino1, dino2, dino3, dino4 ]
[ dino2, dino4 ]
Prompt 2:
The client wants the splash page to display the top three most popular dinosaurs on the site. Write a method that filters the entire list of dinosaurs and returns an array containing the top three most popular dinosaurs.
Example:
[ dino1, dino2, dino3, dino4 ]
[ dino1, dino2, dino4 ]
Prompt 1:
Prompt 2: