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

185
Views
Invert a sequence in JavaScript

I want to invert this sequence: Invert a function like in mathematics(is this exist in programming) What I mean: if f(x)=y --->g(y)=x so g is the inverse function of f.
My attempt was(but still not working):

function seq(num) {
  
  if(num < 2) {return 1; }
  if(num === 2) {return 2; } 
  
  if(num % 2 === 1) {
    const t = (num - 1) / 2;
    return seq(t - 1) + seq(t) + 1;
  }
  
  const t = num / 2;
  return seq(t) + seq(t + 1) + t;
  
}
document.write(_.invert(seq(4)));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There is no known algorithm to programmatically invert a function, baring brute force over the domain. Indeed, such an algorithm, if workable would be a stunning discovery, likely breaking the vast majority of cryptosystems. There are a bunch of different methods for finding the inverse of a function, but they depend on the function in question meeting specific criteria.

The lodash invert function performs an completely different function, swapping keys and values of objects.

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!