Skip to content

FreeCodeCampus/rest-parameters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Freecodecamp solution for a Counting Cards task:

In order to help us create more flexible functions, ES6 introduces the rest operator for function parameters. With the rest operator, you can create functions that take a variable number of arguments. These arguments are stored in an array that can be accessed later from inside the function.

Check out this code:

function howMany(...args) { return "You have passed " + args.length + " arguments."; } console.log(howMany(0, 1, 2)); // You have passed 3 arguments console.log(howMany("string", null, [1, 2, 3], { })); // You have passed 4 arguments. The rest operator eliminates the need to check the args array and allows us to apply map(), filter() and reduce() on the parameters array.

Modify the function sum so that it uses the rest operator and it works in the same way with any number of parameters.

To run this app

clone it :

git clone [email protected]:FreeCodeCampus/rest-operator.git

and run a command in your terminal

node index.js

About

Rest Parameters

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published