image2text

Untitled

Aug 6th, 2019
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // When you get a predefined value based on some variable,
  2. T T e S e S e R e[ SRR G i Bl
  3. const size = 'sm'
  4. // You can write this logic as a bunch of "ifs",
  5. // but then you have to:
  6. let dimension // initialize an empty variable
  7. i (Gl == g’ )] 4 // write a comparison logic
  8. dimension = '10x10" // ...and an assignment logic
  9. } else if (size === 'md') { // ...and repeat a comparison
  10. dimension = '60x25"' // ...and assignment
  11. } else if (size === '19') { // ...and comparison
  12. dimension = '120x80' // ...and assignment
  13. )
  14. // You can also use switch statement. Then you still have to:
  15. let dimension // initialize an empty variable
  16. BASd N EA S I
  17. CalS el S:
  18. dimension = '10x10' // repeat an assignment logic
  19. ER el 8
  20. dimension = '60x25' // ...and repeat an assignment
  21. G Yllete
  22. dimension = '120x80" // ...and repeat an assignment
  23. )
  24. // Instead you can use Map, in that case you only:
  25. const sizes = new Map([ // B define the mapping
  26. ['sm', '10x10'],
  27. IR R0 R I
  28. ['lg', '120x80']
  29. 1)
  30. const dimension = sizes.get(size) // B assign the value
Advertisement
Add Comment
Please, Sign In to add comment