Created
July 9, 2015 18:22
-
-
Save xoddong/48efe0bda921fee06fff to your computer and use it in GitHub Desktop.
Multiply Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.