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

135
Visualizações
Understand Function Javascript

Please help me to understand this code.

function printEven(arr, pow) {
    var res = 1;

    for (var i = 0; i < pow; i++) {
        res = res * arr;
    }  
    return res;
}

console.log(printEven(4,3))
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

As far as I can see it is just a custom implementation of an exponential function.

It effectively calculates arr^pow, or in this case 4**3 or 4 * 4 * 4.

At i = 0, res gets multiplied with arr, 1 * 4 = 4.
At i = 2 it will have calculated 4 * 4 * 4, returning 64.

about 4 years ago · Juan Pablo Isaza Relatório

0

It seems to simply apply a power, so printEven(2,5) returns 2^5 or 32

it's effectly multipling the first input arr to 1 pow times (like 1*2*2*2*2*2)

so console.log(printEven(4,3)) is 64

about 4 years ago · Juan Pablo Isaza Relatório

0

function printEven(arr, pow) {
var res = 1;
for (var i = 0; i < pow; i++){
    
        res = res * arr;
    }  
    return res;
}

console.log(printEven(4,3))
console.log(printEven(5,2))

This code is to find "number ^ times"

example 4 ^ 3 = 4 * 4 * 4 = 64

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=RBAS_OEXPONENT#:~:text=Used%20to%20raise%20a%20number%20to%20the%20power%20of%20an%20exponent.

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