You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Alistair Blake edited this page Feb 14, 2019
·
1 revision
Welcome to the seattle-javascript-401n12 wiki!
Functional Programming examples:
//A function that goes over an array and prints out every element:
function printArray(array) {
for (var i = 0; i < array.length; i++)
print(array[i]);
}
//Pass our action as a function value
function forEach(array, action) {
for (var i = 0; i < array.length; i++)
action(array[i]);
}
//An anonymous function
function sum(numbers) {
var total = 0;
forEach(numbers, function (number) {
total += number;
});
return total;
}
show(sum([1, 10, 100]));