Sum Program using Rest Paramater in JavaScript


Example - REST Parameter

By using REST parametrs we can sum infinite number of arguments as an array

function sum(...argslist)
{
	return argslist.reduce((prev,current)=>{ return prev+current; });
}
sum(1); //Output : 1
sum(1,2,3); //Output : 6


Related

JavaScript Average Program using Arrow Function
JavaScript Product Program using Arrow Function
Sum Program using reduce() method in JavaScript