81.checkSettlesInTime

Write a function named checkSettlesInTime that receives 2 parameters:

  • a Promise
  • a number representing milliseconds - maxTime

The function should return another Promise that will resolve with one of two values:

  • true - if the received Promise settles before maxTime milliseconds passed
  • false - if the received Promise takes longer than maxTime milliseconds to settle

NOTE: by settle we mean that the Promise is either resolved or rejected.

Example 1

// A promise that resolves after 250ms
const promise1 = new Promise((resolve) => {
  setTimeout(() => resolve(), 250);
});

// A promise that rejects after 2500ms
const promise2 = new Promise((_, reject) => {
  setTimeout(() => reject(), 2500);
});

checkSettlesInTime(promise1, 500).then((didSettle) => {
  console.log(didSettle); // should print "true"
});

checkSettlesInTime(promise2, 1000).then((didSettle) => {
  console.log(didSettle); // should print "false"
});