1const list = ['Potato', 'Apple', 'Baguette', 'Elon Musk'];
2console.log(...list); // <- Triple hyphen is what we call a spread
3
4// Output : Potato Apple Baguette Elon Musk
5
6
7
8
9
10
11// ---- Expand for more detailed description ---- //
12
13// Spread syntax (...) allows an iterable such as an array expression
14// or string to be expanded in places where zero or more arguments
15// (for function calls) or elements (for array literals) are expected,
16// or an object expression to be expanded in places where zero or more
17// key-value pairs (for object literals) are expected.
18
19// Spread syntax can be used when all elements from an object or array
20// need to be included in a list of some kind.
21
22// | Mozilla doc in source just below
23// v
1const rgb = [255, 0, 0];
2
3// Randomly change to showcase updates
4setInterval(setContrast, 1000);
5
6function setContrast() {
7 // Randomly update colours
8 rgb[0] = Math.round(Math.random() * 255);
9 rgb[1] = Math.round(Math.random() * 255);
10 rgb[2] = Math.round(Math.random() * 255);
11
12 // http://www.w3.org/TR/AERT#color-contrast
13 const brightness = Math.round(((parseInt(rgb[0]) * 299) +
14 (parseInt(rgb[1]) * 587) +
15 (parseInt(rgb[2]) * 114)) / 1000);
16 const textColour = (brightness > 125) ? 'black' : 'white';
17 const backgroundColour = 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ')';
18 $('#bg').css('color', textColour);
19 $('#bg').css('background-color', backgroundColour);
20}