Sobes.tech
Junior — Senior

Creating a function that returns a Promise instead of a callback

livecode

Task condition

The function asyncAuth(cb) takes a callback, which receives a possible error (the first parameter) and data received from the server (the second parameter). asyncAuth((err, result) => {}); Your task is to implement the auth() function, which internally calls asyncAuth but returns a Promise instead of using a callback. @returns {Promise} function auth() { // asyncAuth((err, result) => {}); }

The tryAuth() function should use auth() and, in case of an error, perform N additional attempts. If after all attempts the error persists, it should reject the promise with the last received error. @returns {Promise} function tryAuth(attempts) { }