Created
September 17, 2018 11:53
-
-
Save ristaa/ac49e4d3afd826c79e700549ed645e5c to your computer and use it in GitHub Desktop.
Spread/Rest operator
This file contains 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
// 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