SLCH

2020 - JS interview - tasks

Aug 19th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. 1)
  2. You are given an array of servers that start to crash from some server.
  3. The server health check runs asynchronously and returns a Promise <boolean>.
  4. Only one server can be checked for operability at a time.
  5. It is necessary to write the findServer function, which will receive a list of servers and function functions as input,
  6. but it will return a Promise, which will be resolved with the address of the first failed server.
  7. The solution should run the check function as few times as possible.
  8. Async / await and generators cannot be used.
  9.  
  10. Example
  11. const servers = ['srv-a', 'srv-b', 'srv-c', 'srv-d'];
  12. const check = (name) => new Promise((res) => setTimeout(res, 100)).then(() => name === 'srv-a');
  13.  
  14. findServer(servers, check); // Promise.resolve('srv-b')
  15.  
  16. 2)
  17. You need to implement the method
  18. load (url, priority) returns Promise
  19. The load method works according to the following logic - the resource starts loading only then,
  20. when we received a response from all resources previously requested with a higher priority.
  21. If no resources are loaded at the time of the call or their priority is lower or equal to priority -
  22. you need to start downloading immediately.
  23. It is guaranteed that there will be no calls with different priority values for the same url.
  24.  
  25. 3)
  26. You need to write a function that converts a string from Camel Case to Snake Case.
  27. Examples:
  28. camelToSnake ('updatedAt') // updated_at
  29. camelToSnake ('XmlHttpRequest') // xml_http_request
Advertisement
Add Comment
Please, Sign In to add comment