Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Array featuring our ancient text. Each element is sorted randomly.
- const returnValues = [
- "Hakuna",
- "Matata",
- "It means",
- "No worries",
- "For the rest of your days"
- ].sort(() => (Math.random() > 0.5 ? 1 : -1));
- //We pass in our retVal and index which will be used during the mapping stage. A function is returned
- //and the anonymous function returns a promise that'll output the values from the returnValues array anywhere between 0 and 10 seconds.
- //When this promise resolves we will display in a random order at a random time, elements from the returnValues array.
- const createService = (retVal, index) => () =>
- new Promise(resolve =>
- setTimeout(() => {
- console.log(`${index}. ${retVal}`);
- resolve(retVal);
- }, Math.random() * 10000)
- );
- //Creating new array with an amount of createService functions equal the length of the returnValues array.
- const services = returnValues.map(createService);
- //Loop through the services array and call each function within it.
- services.forEach(service => {
- service();
- });
- //document.getElementById("ui").innerHTML = `***Display to the DOM our Status.
- //If the status is resolved display them. For any that have not resolved then display PENDING text***`;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement