-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathpractice.js
More file actions
326 lines (207 loc) · 8.19 KB
/
practice.js
File metadata and controls
326 lines (207 loc) · 8.19 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
Once you complete a problem, refresh ./SpecRunner.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 arr = [10,20,30];
// Do not edit the code above.
/*
Create a function named 'first' that is given 'arr' as an argument.
Return the first item in the given array.
*/
//Code Here
////////// PROBLEM 2 //////////
// Do not edit the code below.
var arr = [40,50,60];
// Do not edit the code above.
/*
Create a function named 'last' that is given 'arr' as an argument.
Return the last item in the given array.
*/
//Code Here
////////// PROBLEM 3 //////////
// Do not edit the code below.
var family = ['Tyler', 'Jordyn', 'Ryan', 'Chelsey', 'Ireland'];
// Do not edit the code above.
/*
Create a function named 'looper' that is given family as it's only argument.
Loop through the given array and alert every item in the array.
*/
//Code Here
////////// PROBLEM 4 //////////
// Do not edit the code below.
var letters = ['A', 'B', 'C', 'D', 'E'];
// Do not edit the code above.
/*
Write a function called reversedLooper that is given letters as it's only argument.
Loop backwards, starting at the end of the letters array, alerting every item in the array.
*/
//Code Here
////////// PROBLEM 5 //////////
// Do not edit the code below.
var nums = [1,2,3,6,22,98,45,23,22,12];
// Do not edit the code above.
/*
Write a function named evenFinder that is given nums as it's only argument.
Return an array that contains the even numbers from the nums array.
*/
//Code Here
/////////////////////// EXTRA PRACTICE PROBLEMS BELOW ////////////////////
////////// MOVE ONTO NEXT SECTION BEFORE WORKING ON THESE ////////////////
////////// PROBLEM 6 //////////
// Do not edit the code below.
var numbersArray = [1,2,34,54,55,34,32,11,19,17,54,66,13];
// Do not edit the code above.
/*
Write a function called divider that is given one argument, numbersArray.
Have divider return an array with the first item in the array being the evens array (all the even values from numbersArray)
and the second item in the array being the odds array (all the odd values from numbersArray).
*/
//Code Here
////////// PROBLEM 7 //////////
// Do not edit the code below.
var getRandomArbitrary = function() {
return Math.floor(Math.random() * 30);
};
// Do not edit the code above.
/*
var numbers = [0,3,4,5,6,7,9,14,17,24,25,26,29,30];
Above you're given a function (getRandomArbitrary) that will return a random number between 0 and 30.
There is also a commented out array full of numbers to help you visualize what your function will be receiving.
Write a function named finder that will take in an array as an argument.
In the function create a variable called randomNumber and set it to the invocation of getRandomArbitrary.
Loop through the array to see if randomNumber is in the array.
If it is, return true, if it's not, return false
*/
//Code Here
////////// PROBLEM 8 //////////
// Do not edit the code below.
var myGroceryList = ['chips', 'pizza', 'hotpockets', 'MtnDew', 'corndogs'];
// Do not edit the code above.
/*
Here we're going to write a function that mimics going shopping and checking things off of our grocery list and adding new items to our list.
Write a function called removeItem that is given two arguments, the first is myGroceryList, and the second is an item to remove from myGroceryList.
If the second argument (or the item to add or remove) matches an item in myGroceryList, remove that item from the your grocery list and return the new, updated grocery list.
Once you do that, write another function called addItem that is given two arguments, the first is myGroceryList and the second is an item to add to your grocery list.
In addItem add the item you passed in to myGroceryList then return the new, updated grocery list.
In both removeItem and addItem check to see if the 'myGroceryList' and 'item' arguments are truthy.
If they are not, return an empty array.
Here are some examples of calling your functions and what should be returned:
removeItem(myGroceryList, 'chips') --> ['pizza', 'hotpockets', 'MtnDew', 'corndogs'];
addItem(myGroceryList, 'Jerky') --> ['pizza', 'hotpockets', 'MtnDew', 'corndogs', 'Jerky'];
removeItem(myGroceryList) --> [];
addItem() --> [];
*/
//Code Here
////////// PROBLEM 9 //////////
/*
Write a function called maker that creates an array, fills that array with numbers from 1 to 215, then returns the array.
*/
//Code Here
////////// PROBLEM 10 //////////
// Do not edit the code below.
var numbers = [5, '9', 16, 19, '25', '34', 48];
// Do not edit the code above.
/*
Write a function called addTen that is given 'numbers' as it's only argument.
Return a new array after adding ten to each item in numbers.
Your output should look like this -> [15, 19, 26, 29, 35, 44, 58]
*/
//Code Here
////////// PROBLEM 11 //////////
// Do not edit the code below.
var num1 = Math.floor(Math.random() * 30);
var num2 = Math.floor(Math.random() * 30);
var arr1 = [];
var arr2 = [];
for(var i = 0; i < num1; i++){
arr1.push(i);
}
for(var i = 0; i < num2; i++){
arr2.push(i);
}
// Do not edit the code above.
/*
Above is some code that adds a random number of values to both arr1 and arr2.
Write a function called 'longer' that is given arr1 and arr2 as it's only arguments.
Return the longer of the two arrays.
*/
//Code Here
/*
As a continuation of the previous problem, write another function called 'both'.
Your 'both' function will be given two arguments, arr1 and arr2 (from the previous example).
'both' should return a new array with the matching numbers found in both arr1 and arr2.
Example: var arr1 = [1,2,3,4]; var arr2 = [2,4,5,6]; newArray // [2,4]
*/
//Code Here
////////// PROBLEM 12 //////////
// Do not edit the code below.
var devMountainEmployees = [];
var joe = {
name: 'Joe',
position: 'Instructor',
spiritAnimal: 'Honey Badger'
};
var cahlan = {
name: 'Cahlan',
position: 'CEO',
spiritAnimal: 'butterfly'
};
var ryan = {
name: 'Ryan',
position: 'Marketing',
spiritAnimal: 'fox'
};
var colt = {
name: 'Colt',
position: 'Everything really',
spiritAnimal: 'Young Male Horse'
};
// Do not edit the code above.
/*
Above you're given an empty array and four variables containing objects.
Fill the devMountainEmployees array with those four objects. Do this in either
the global scope or in a function. If done in a function, invoke it.
After that, console.log the length of the Array and make sure that it's equal to 4.
*/
//Code Here
/*
Now let's say Cahlan has to take a leave of absence.
Loop through your devMountainEmployees until you find cahlan, then remove him from the array.
*/
//Code Here
////////// PROBLEM 13 //////////
/*
A very clean way to pass around large LISTS (arrays) of COLLECTIONS (objects) of data is to have an array full of objects.
Create an empty array called users.
*/
//Code Here
/*
Now add three user objects to your users array. Each user object should contain the following properties: name, email, password, username.
Include the following user1 object as one of the objects in your array.
MAKE SURE TO DO THIS IN THE SECTION BELOW WHERE USER1 IS DECLARED
*/
// Do not edit the code below.
var user1 = {
name: 'Mark McIver',
email: 'mark.mciver@devmounta.in',
password: 'hunter2',
username: 'ihazcode'
};
// Do not edit the code above.
//Code Here
/*
Now you have a very common data structure.
Twitter is a good use case.
It's easy to imagine that your followers list on Twitter is an array full of objects and those objects contain properties about the specific person you follow.
Now let's say that Mark decided to delete his account.
Loop through your array of objects until you find Mark's account (use his email, mark.mciver@devmounta.in, to find him).
Once you find the array index he's located in, delete him from the array.
*/
//Code Here
/*
The activity we just did is very much how data works in 'the real world'.
*/