Skip to content

Instantly share code, notes, and snippets.

@gaand
Last active October 5, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaand/3148d7ab2478d7c23254 to your computer and use it in GitHub Desktop.
Save gaand/3148d7ab2478d7c23254 to your computer and use it in GitHub Desktop.
product, two version
var product2 = function product2(nums) {
var result = 1;

  for (var i = 0; i < nums.length; i++) {
    result *= nums[i];
  }

  return result;

};

var product = function product () {
  var result = 1;

  // the arguments object contains all arguments passed
  // to the function
  // it has a length property and it elements
  // can be accessed with []

  for (var i = 0; i < arguments.length; i++) {
    result *= arguments[i];
  }

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