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

134
Views
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 answers
Answer question

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 Report

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 Report

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