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

147
Views
Is it possible to alter Math Equations in a loop?

Take this array of math expressions, which are NOT strings:

let eqs = [ 1+n, 2+n, 3+n]

Is it possible to loop through these equations and modify them WITHOUT evaluating them in javascript somehow?

eqs.map(eq => eq + 1)

...and return this:

// [ 1+n+1, 2+n+1, 3+n+1]

Is something like that even possible at all? Doesn't have to be .map() just using that as an example. Doesn't have to be that syntax, i just can't imagine what the syntax for something like that might be is all...

Been googling around but I haven't found much yet...but I am getting the feeling that this might NOT be possible...is that the case?

Thank you for any assistance :-)

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

0

This could be a starting point:

let eqs = [ "1+n", "2+n", "3+n"]
let modeqs = eqs.map(eq => eq+"+1")
console.log(modeqs);
[0,8,15].map(n=>console.log(modeqs.map(s=>(new Function('n','return '+s))(n))))

The updated snippet now contains a part that converts each formula into a function and then executes it in a .map() structure.

Alternatively you could start with and manipulate actual functions:

let eqs = [ n=>1+n, n=>2+n, n=>3+n]
let modeqs = eqs.map(fn => eval(fn.toString()+"+1") )
console.log(modeqs);

[0,8,15].map(n=>console.log(modeqs.map(fn=>fn(n))));

The last example uses eval() which by many is seen as a possible security risk. So, please think about where and when you want to use it.

about 4 years ago · Juan Pablo Isaza Report

0

You can do that

let eqs = ['1+n', '2+n', '3+n']
console.log(eqs.map(eq => `${eq}+1`))

If you want another things . Comment below.

about 4 years ago · Juan Pablo Isaza Report

0

You can use Template literals (Template strings)

Demo :

let eqs = ['1+n', '2+n', '3+n'];

let res = eqs.map(eq => `${eq}+1`);

console.log(res);

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!