function sum(...numbers) { // The rest operator is three dots followed by the variable name; by convention, it is typically called 'rest' // The rest operator must be the last parameter in the function definition return numbers.reduce((acc, val) => acc + val, 0); } // The reduce method is used to sum all the numbers in the array
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter