Skip to content

Instantly share code, notes, and snippets.

@seb-thomas
Created February 19, 2017 12:04
Show Gist options
  • Save seb-thomas/c8630d3653e11d2c81022746d5ec23d3 to your computer and use it in GitHub Desktop.
Save seb-thomas/c8630d3653e11d2c81022746d5ec23d3 to your computer and use it in GitHub Desktop.
Pass an argument to Array.map
var createSquareFuncWithAdjustment = function(offset) {
return function(val) { return Math.round((val - offset) * 5 / 9); };
};
var fahrenheit = [0, 32, 45, 50, 75, 80, 99, 120];
fahrenheit.map(createSquareFuncWithAdjustment(32));
@seb-thomas
Copy link
Author

const createSquareFuncWithAdjustment = offset => val => Math.round((val - offset) * 5 / 9);

const fahrenheit = [0, 32, 45, 50, 75, 80, 99, 120];
fahrenheit.map(createSquareFuncWithAdjustment(32));

@seb-thomas
Copy link
Author

As a function declaration:

function createSquareFuncWithAdjustment(offset) {
    return val => Math.round((val - offset) * 5 / 9);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment