DEV Community

Discussion on: Using Finite State Machines to Simplify Frontend User Flow

Collapse
 
valeriavg profile image
Valeria • Edited

This code could be simplified with binary masks:

state |= 0b10 // to "activate" first avatar
state |= 0b01 // to "activate" second avatar
state &= 0b01 // to "deactivate" first avatar
state &= 0b10 // to "deactivate" second avatar
Boolean(state & 0b10) // to check if first avatar is "activated"
Boolean(state & 0b01) // to check if second avatar is "activated"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
codemochi profile image
Code Mochi

Ooh that's super slick, thanks so much for the suggestion!