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

217
Views
stopping a higher order function generating numbers at certain number

I have a function that takes another function that generates consecuitive numbers

(numbers can be generated from any start point)

also the function takes a value which it should stop before

i can get it to work from zero up to the required limit but not if for expample it starts at 1

these are requirements:

returns a function on first invocation
✓ returns given value on first call
✓ Subsequent invocations emits consecutive integers (1 ms)
✓ exclusively emits undefined when surpassed limit (not inclusive) (1 ms)
✕ exclusively emits undefined when surpassed limit (not inclusive) when generator does not start at 0

hof.to = function (funcfrom, n) {
  counter = n;
  return function () {
    if (counter > 0) {
      counter--;
      return funcfrom();
    }
  };
};
about 4 years ago · Juan Pablo Isaza
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!