I am fairly new to js and I have been looking at the Mozilla Developer site. Under the functions section, I can't seem to grasp the following
function map(f,a) {
var result = [], // Create a new Array
i;
for (i = 0; i != a.length; i++)
result[i] = f(a[i]);
return result;
}
particulary, this line "result[i] = f(a[i]);"
From Mozilla: Function expressions are convenient when passing a function as an argument to another function. The following example shows a map function being defined and then called with an anonymous function as its first parameter
Can you help explain this?
Here is a link for reference. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions