Intermediate Algorithm Scripting - Arguments Optional

Neat solution using the rest parameter syntax from ES6.

function addTogether(x, ...y) {
	if (typeof(x) == 'number') {
		if (y.length == 0) {
			// if one argument is passed
			return function(y) {
				return typeof(y) == 'number' ? x + y : undefined;
		} else {
			// if two arguments or more are passed
			return (typeof(y[0]) == 'number') ? x + y[0] : undefined;
	} else {
		return undefined;

Challenge: Arguments Optional

Link to the challenge:

Hi @zctyjmt !

Are you looking for feedback or are you looking to contribute your solution to the guide post?

If you are looking for feedback, then you should amend your post to say that.

If you are looking to contribute to the guide, then you need to make a post in the #contributors section.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.