Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. //Array featuring our ancient text. Each element is sorted randomly.
  2. const returnValues = [
  3. "Hakuna",
  4. "Matata",
  5. "It means",
  6. "No worries",
  7. "For the rest of your days"
  8. ].sort(() => (Math.random() > 0.5 ? 1 : -1));
  9.  
  10. //We pass in our retVal and index which will be used during the mapping stage. A function is returned
  11. //and the anonymous function returns a promise that'll output the values from the returnValues array anywhere between 0 and 10 seconds.
  12. //When this promise resolves we will display in a random order at a random time, elements from the returnValues array.
  13. const createService = (retVal, index) => () =>
  14. new Promise(resolve =>
  15. setTimeout(() => {
  16. console.log(`${index}. ${retVal}`);
  17. resolve(retVal);
  18. }, Math.random() * 10000)
  19. );
  20.  
  21. //Creating new array with an amount of createService functions equal the length of the returnValues array.
  22. const services = returnValues.map(createService);
  23.  
  24. //Loop through the services array and call each function within it.
  25. services.forEach(service => {
  26. service();
  27. });
  28.  
  29.  
  30.  
  31. //document.getElementById("ui").innerHTML = `***Display to the DOM our Status.
  32. //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