Question: (Javascript) I need help in writing a function, `postponeWithArgs`, that accepts a callback and a delay in milliseconds as arguments. `postponeWithArgs` should return a new

(Javascript)

I need help in writing a function, `postponeWithArgs`, that accepts a callback and a delay in

milliseconds as arguments. `postponeWithArgs` should return a new function that

accepts any number of arguments. When the returned function is called, it should

invoke the callback after the given delay, passing any arguments it receives to

the callback.

Examples

const greet = (person) => console.log('Hello ' + person + '!');

const slowGreet = postponeWithArgs(greet, 1000);

slowGreet('Rose'); // prints 'Hello Rose!' after 1000 ms

slowGreet('Alex'); // prints 'Hello Alex!' after 1000 ms

const printSum = (num1, num2) => console.log(num1 + num2);

const slowPrintSum = postponeWithArgs(printSum, 500);

slowPrintSum(4, 3); // prints '7' after 500 ms

slowPrintSum(2, 8); // prints '10' after 500 ms

***********************************************************************/

function postponeWithArgs(cb, delay) {

// your code

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!