Given the following multi-message "Dialog", how would you represent this in Javascript or Typescript?
Note: please avoid using any 3rd party libraries in these exercises.
Using your representation from Exercise 1, write a function that takes as parameters a Dialog
and a User
object and returns the number
of messages sent to the user.
func messages_sent_to(user: User, dialog: Dialog) -> number
The User class has the following relevant attributes:
school_year
: a string or enum containing FRESHMAN, SOPHMORE, JUNIOR, SENIORis_transfer
: a boolean that'strue
for transfer studentscurrent_state
: a reference (e.g., pointer, numeric id, etc.) to a specificState
object in aDialog
Assume the user starts off at the upper most state in the Dialog
tree.
User = {
school_year: 'FRESHMAN' | 'SOPHMORE' | 'JUNIOR' | 'SENIOR'
is_transfer: boolean
current_state: ref State
}