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

92
Views
Closure techniques to hide function details

I have a recursive function that I would like to hide as an implementation detail. Here is are the two functions that I have to start:

function f(n) {
    return fIter(2,1,0,n);
}
function fIter(a,b,c,n) {
    return n===0 ? c : fIter(a+2*b+3*c, a,b,n-1);
}
console.log(f(5))

What would be the suggested way to hide the implementation details? Two examples that came to mind were:

const f = n => (function fIterative(a, b, c, n) {
    return (n===0) ? c : fIterative(a+2*b+3*c, a, b, n-1)
})(2,1,0,n);
console.log(f(5))

And:

function f(n) {
    function fIter(a,b,c,n) {
        return n===0 ? c : fIter(a+2*b+3*c, a,b,n-1);
    }
    return fIter(2,1,0,n);
}
console.log(f(5))

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!