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