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

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

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 Denunciar

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 Denunciar

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 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