Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ristaa
Created September 17, 2018 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ristaa/ac49e4d3afd826c79e700549ed645e5c to your computer and use it in GitHub Desktop.
Save ristaa/ac49e4d3afd826c79e700549ed645e5c to your computer and use it in GitHub Desktop.
Spread/Rest operator
// Spread operator
function fruits(apples, bananas, pears){
console.log(apples);
console.log(bananas);
console.log(pears);
}
fruitsNo = [7, 9, 14];
fruits(...fruitsNo);
/*
7
9
14
*/
// Rest operator
function getFruitsByBasket(apples, bananas, pears) {
var fruits = [...arguments];
var howMany = fruits.map(function (fruit){
return fruit;
});
console.log(`In baskets, there are ${howMany} fruits.`)
}
getFruitsByBasket(6, 7, 8); // In baskets, there are 6,7,8 fruits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment