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

186
Views
Why isn't my callback on the array working?

I wrote the code to iterate through a given array and then invoke the function subtractTwo on each element. However, when I run the function map the array argument returns unchanged. Does anyone know why this might be?

// create the subtractTwo function, callback function 
function subtractTwo (number) {
    return number - 2; 
}

// create higher-order function, map 
function map (array, callback) {
  // initiate a for loop, looping through the array and invoking the callback on each element; 
  for (let i = 0; i < array.length; i ++) { 
    callback(array[i]);
    
  }
  //return the new array
  return array;
}


//console.log(subtractTwo(4));
// Uncomment these to check your work!
console.log(typeof subtractTwo); // should log: 'function'
console.log(typeof map); // should log: 'function'
console.log(map([3,4,5], subtractTwo)); // should log: [ 1, 2, 3 ]```
about 4 years ago · Juan Pablo Isaza
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!