-
Notifications
You must be signed in to change notification settings - Fork 759
/
Copy pathdestructuring.js
102 lines (68 loc) · 2.55 KB
/
destructuring.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
Once you complete a problem, refresh ./destructuring.html in your browser and check to see if the problem's test(s) are passing.
Passed tests will be indicated by a green circle.
Failed tests will be indicated by a red X.
You can refresh the page at any time to re-run all the tests.
*/
////////// PROBLEM 1 //////////
// Do not edit the code below.
var carDetails = {
color: 'red',
make: 'toyota',
model: 'tacoma',
year: 1994
}
// Do not edit the code above.
/*
Use object destructuring to save the property values from the object carDetails into new variables.
*/
//Code Here
////////// PROBLEM 2 //////////
/*
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.
*/
function greeting( obj ) {
//Code Here
// Do not edit the code below.
return 'Hello, ' + title + ' ' + firstName + ' ' + lastName + '!';
// Do not edit the code above.
}
////////// PROBLEM 3 //////////
/*
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
////////// PROBLEM 4 //////////
/*
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
////////// PROBLEM 5 //////////
/*
Now we will use object destructuring as the function's parameter instead of destructuring the object inside of the function declaration.
Example:
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
////////// PROBLEM 6 //////////
/*
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