Skip to content

Instantly share code, notes, and snippets.

@valerymelou
Created May 20, 2018 10:57
Show Gist options
  • Save valerymelou/1829e21bc03e7a6809b3530c7a9562dc to your computer and use it in GitHub Desktop.
Save valerymelou/1829e21bc03e7a6809b3530c7a9562dc to your computer and use it in GitHub Desktop.
// Example 1
const order = [20.17, 18.67, 1.50, "cheese", "eggs", "milk", "bread"];
const [total, subtotal, tax, ...items] = order;
console.log(total, subtotal, tax, items); // 20.17 18.67 1.5 ["cheese", "eggs", "milk", "bread"]
// Example 2
function sum(...nums) {
let total = 0;
for(const num of nums) {
total += num;
}
return total;
}
console.log(sum(10, 20, 30)); // 60
console.log(sum(20, 20)); // 40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment