Using javascript map with a function that has two arguments

Use an anonymous function:

values.map(
  function(x) { return squarefuncwithadjustment(x, 2); }
);

As of ES6 you can use:

.map(element => fn(element, params))

In your case if I want to use 3 as adjustment:

values = [1,2,3,4]
values.map(n => squarefuncwithadjustment(n, 3))

You could use a callback creation function:

var createSquareFuncWithAdjustment = function(adjustment) {
    return function(x) { return (x * x) + adjustment; };
};

values = [1, 2, 3, 4];
values.map(createSquareFuncWithAdjustment(2)); // returns [3, 6, 11, 18]

Tags:

Javascript