Skip to content

Instantly share code, notes, and snippets.

@xoddong
Created July 9, 2015 18:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoddong/48efe0bda921fee06fff to your computer and use it in GitHub Desktop.
Save xoddong/48efe0bda921fee06fff to your computer and use it in GitHub Desktop.
Multiply Function
var multiply = function() {
var _args = [].slice.call(arguments);
var length = _args.length;
if (Array.isArray(this)) {
this.push(_args.pop());
if (this.length === 3) {
return (this[0] * this[1] * this[2]);
}
return multiply.bind(this);
}
return multiply.bind(_args);
};
@xoddong
Copy link
Author

xoddong commented Jul 9, 2015

var multiply = function() {
var _args = [].slice.call(arguments);
if (_args.length === 3) {
return _args[0] * _args[1] * _args[2];
} else {
return function() {
_args.push([].slice.call(arguments).pop());
return multiply.apply(this, _args);
};
}
};

This would be a simpler solution.

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