-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patharraySpreadOperator.js
More file actions
48 lines (31 loc) · 1.71 KB
/
arraySpreadOperator.js
File metadata and controls
48 lines (31 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
// OBJECTIVE ////////////////////////////////////////////////////////////////////////////////////////////////
// Using the array spread operator (...)
// SUMMARY //////////////////////////////////////////////////////////////////////////////////////////////////
// What is the problem?:
// You need to take the items from one array and push them into another array.
// What is the BEST solution?
// Use the Array Spread operator when you want to push ALL the items from one array into the other.
// What are the special components of these solutions?:
// 1. array spread operator (...)
// What needs work?
// 2. convert arguments to array
// 4. destructuring
// Links of interest
// https://davidwalsh.name/spread-operator
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// COMBINING ARRAYS /////////////////////////////////////////////////
const numbersCA = [1,2,3,4,5];
const multiplierCA = [6,7,8,9];
// WITHOUT ARRAY SPREAD OPERATOR //
// includes the mulitplier as a single array added to numbers
// So bascially when you push multiplierCA into numbersCA, the multiplierCA is simply pushed into the array as a single entity.
console.log(numbersCA.push(multiplierCA)); // 6
// WITH ARRAY SPREAD OPERATOR //
// includes the multiplier numbers with the numbers
// However, when you use the array spread operator, each item in the multiplierCA array is pushed into the numbersCA array.
console.log(numbersCA.push(...multiplierCA)); // 10
// USING MATH FUNCTIONS ////////////////////////////////////////////
let numbersMF = [9, 4, 7, 1];
console.log(Math.min(...numbersMF)); // 1
console.log(Math.max(...numbersMF)); // 9