Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. function roadRadar(input) {
  2. let limits = {
  3. 'motorway': x => 130 - x,
  4. 'interstate': x => 90 - x,
  5. 'city': x => 50 - x,
  6. 'residential': x => 20 - x
  7. }
  8. let speedingUp = {
  9. 'less': '',
  10. 20: 'speeding',
  11. 40: 'excessive speeding',
  12. 'more': 'reckless driving'
  13. }
  14. let speed = Number(input[0]);
  15. let area = input[1];
  16. let diff = limits[area](speed);
  17.  
  18. function speeding(diff) {
  19. return diff >= 0 ? speedingUp['less'] :
  20. diff >= -20 ? speedingUp[20] :
  21. diff >= -40 ? speedingUp[40] : speedingUp['more']
  22. }
  23. console.log(speeding(diff));
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement