Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda