Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda