Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // When you get a predefined value based on some variable,
- T T e S e S e R e[ SRR G i Bl
- const size = 'sm'
- // You can write this logic as a bunch of "ifs",
- // but then you have to:
- let dimension // initialize an empty variable
- i (Gl == gā )] 4 // write a comparison logic
- dimension = '10x10" // ...and an assignment logic
- } else if (size === 'md') { // ...and repeat a comparison
- dimension = '60x25"' // ...and assignment
- } else if (size === '19') { // ...and comparison
- dimension = '120x80' // ...and assignment
- )
- // You can also use switch statement. Then you still have to:
- let dimension // initialize an empty variable
- BASd N EA S I
- CalS el S:
- dimension = '10x10' // repeat an assignment logic
- ER el 8
- dimension = '60x25' // ...and repeat an assignment
- G Yllete
- dimension = '120x80" // ...and repeat an assignment
- )
- // Instead you can use Map, in that case you only:
- const sizes = new Map([ // B define the mapping
- ['sm', '10x10'],
- IR R0 R I
- ['lg', '120x80']
- 1)
- const dimension = sizes.get(size) // B assign the value
Advertisement
Add Comment
Please, Sign In to add comment