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

203
Views
Need to use a function inside the map of a list

I'm just learning JavaScript and I'm trying to do the following. Let's say I have the following function:

f(a,b) {return(a+b)}

And now I have a list of for example the following:

list = [1,2,3]

What I would like to do is map for that list in which I call the function above f with a predefined value and each value of the list. I've tried this:

listB = list.map(x => f(x+23))

But it returns a NaN, and if I add some brackets that snippet returns undefined.

What's going on and how can I solve it?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Should be f(x, 23) instead of f(x + 23):

function f(a,b) {return(a+b)}

listA = [1,2,3]
listB = listA.map(x => f(x,23))

console.log(listB)

about 4 years ago · Juan Pablo Isaza Report

0

you can re-write it as

const list = [1, 2, 3, 4];
const listb = list.map(f);

function f(num) {
  return num + 23;
}
about 4 years ago · Juan Pablo Isaza Report

0

you have error in your function call f(x + 23). This is because your function f expects 2 arguments, and you forward only one. number + undefined -> NaN

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!