forked from DevMountain/javascript-3-afternoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdestructuring.js
More file actions
64 lines (33 loc) · 2.15 KB
/
destructuring.js
File metadata and controls
64 lines (33 loc) · 2.15 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// ========================
// DESTRUCTURING
// ========================
// Use object destructuring to save the property values from the object carDetails into new variables.
var carDetails = {
color: 'red',
make: 'toyota',
model: 'tacoma',
year: 1994
}
// CODE HERE
// ========================
// In the function below named greeting, it is receiving an object as a parameter. Use object destructuring to save the object properties to new variables. The property names are firstName, lastName, and title. Return the concatenated string.
function greeting( obj ) {
// CODE HERE
return 'Hello, ' + title + ' ' + firstName + ' ' + lastName + '!';
}
// ========================
// Write a function called totalPopulation that will take in an object. That object will have 4 properties named utah, california, texas and arizona. The property values will be numbers. Use object destructuring to save the property values to new variables. Sum up the values and return the total number.
// CODE HERE
// ========================
// Write a function called ingredients that will take in an object. This object will have 3 properties named carb, fat, and protein. The property values will be strings. Use object destructuring to save the property values to new variables. Push these new variables to an array and return the array.
// CODE HERE
// ========================
// Now we will use object destructuring as the function's parameter instead of destructuring the object inside of the function declaration. See the example below:
// function example( {one, two, three} ) {
// return one + two + three
// }
// Write a function called largeNumbers that will take a destructured object as it's parameter. The object properties will be named first, second, and third and their values will be numbers. Find the smallest number of the three and return that number.
// CODE HERE
// ========================
// Write a function called numberGroups that will take a destructured object as it's parameter. The object properties will be named a, b, and c and their values will be arrays of numbers. Find the longest array and return that array.
// CODE HERE