Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
How to implement the code in after function?

How to implement the code after function? It should invoke function only after the third time

function after(count, funct) {
  // code...
}

var called = function () {
  console.log("hello");
};

var afterCalled = after(3, called);
afterCalled(); // --> nothing is printed
afterCalled(); // --> nothing is printed
afterCalled(); // --> "hello" is printed

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could return a function which decrements the counter and if zero it calls the handed over function.

function after(count, funct) {
    return function () {
        if (!--count) funct();
    };
}

var called = function () {
  console.log("hello");
};

var afterCalled = after(3, called);
afterCalled(); // --> nothing is printed
console.log('.')
afterCalled(); // --> nothing is printed
console.log('.')
afterCalled(); // --> "hello" is printed
console.log('.')
afterCalled(); // --> nothing is printed

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!