Skip to content

Instantly share code, notes, and snippets.

@troyscott
Last active August 29, 2015 14:06
Show Gist options
  • Save troyscott/f8f748fcd3c72b4be3f2 to your computer and use it in GitHub Desktop.
Save troyscott/f8f748fcd3c72b4be3f2 to your computer and use it in GitHub Desktop.
Eloquent JS - Functions // source http://jsbin.com/diteto/11
function forEach(array, action) {
for(var i = 0; i < array.length;i++) {
action(array[i]);
}
}
function sum(numbers) {
var total = 0;
forEach(numbers, function (number){
total += number;
console.log("Running Total: " + total);
});
return total;
}
var a = [1, 2, 3];
console.log(sum(a));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment