Array of functions sharing a parameter

This codeblock creates an array of functions stored in “arrayOfFunctions” which all share a parameter. it gets called afterwards inside an alert, just to show how you would call a function in the array.

var arrayOfFunctions = [
  function(a) { return 1 * a - 8; },
  function(a) { return (a + 5) * (a + 1) * (a + 4); },
  function(a) { return a * a - 3; },
  function(a) { return a % 2; }
];

test of function
1 being the parameter and 0 targeting the first function in the array

console.log(arrayOfFunctions[0](1)); //-7 

Add your comment