-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestparameterandfunction.js
More file actions
24 lines (13 loc) · 921 Bytes
/
restparameterandfunction.js
File metadata and controls
24 lines (13 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// JavaScript .rest parameter in a function and destructuring
// spread operator unpacks things that are in an itterable like an array it unpacks that.
// ...rest operator does the opposite and actually packs the rest of the things in an itterable like an array.
// const currencryConverter = (rate, tax, val, ...amounts) => console.log(rate, tax, val, amounts);
// currencyConverter(1.25, 5, 10, 23, 44, 87);
const currencryConverter = (rate, ...amounts) => amounts.map((amount) => rate * amount);
const converted currencyConverter(1.25, 5, 10, 23, 44, 87);
console.log(converted);
// this is the ...rest parameter it will take the rest of the array or itterable and package them into a new array.
const teams = ['You', 'They', 'Jason', 'Nathan', 'Jared'];
const [capt, coCapt, ...team] = teams;
console.log(capt, coCapt, team);
// this is how to use the ...rest parameter in a function and use destructuring