-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise-1.js
More file actions
527 lines (308 loc) · 17 KB
/
exercise-1.js
File metadata and controls
527 lines (308 loc) · 17 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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
// ***For all the exercises, be sure to log the output of the function to the console.***
/************************************************************************************/
// Write a JavaScript function that iterates the integers from 1 to 100. For multiples of 3 print "TEK" instead of the number and for multiples of 5, print "camp." For numbers that are multiples of both 3 and 5, print "TEKcamp."
//your code...
function tekCamp() {}
// tekCamp();
/************************************************************************************/
//Write a function that converts the current temperature from Fahrenheit to Celsius.
//your code...
function farenheitCelsius() {
}
/************************************************************************************/
//Write a function that converts the Celsius temperature back to Fahrenheit.
//your code...
function celsiusFarenheit() {
}
/************************************************************************************/
// Write a function to determine if someone is old enough to vote. The function should return a boolean of true or false.
//your code...
function canVote(age) {
return false;
}
/************************************************************************************/
// Write a function that converts a string to an array. It should return an array.
//your code...
function strToArr() {
return [];
}
/************************************************************************************/
// Write a function that reverses your telephone number. It should return the reversed telephone number.
//your code...
function reversePhone(number) {
}
/************************************************************************************/
// Write a function that returns a car object using some given info about your car. Required inputs are the make, model, year, and color.
//your code...
/************************************************************************************/
// Write a function that accepts a list of numbers. The function should identify each number as being even or odd. The function should output a set of key value pairs, with the key being the number, and the value being the string "even" or "odd".
//example : [10,23,3,4] => function() => {10 : 'even', 23 : 'odd', 3 : 'odd', 4 : 'even'}
//your code...
/************************************************************************************/
const numbers = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
// Write a "for" loop that console.log()'s the first value in the array, and every 3rd number, i.e. 0, 3, 6, 9: the zeroth, third, sixth, and ninth values.
//your code...
/************************************************************************************/
const foodArray = [ 'potatoes', 'tamales', 'lemon','strawberries','chocolate', 'pudding', {program : 'TEKcamp'} ];
//access the value of the last element of the array and set it to a variable called school. print the school variable to the console.
const adjectiveArray = [ 'salty', 'spicy', 'sour', 'sweet', 'rich','creamy','amazing'];
// Using both the foodArray and the adjectiveArray, write "for" loop that console.log()'s a sentence for each corresponding value in the arrays. Add the word "is" or "are" depending on if the food is singular or plural. i.e. "Potatoes are salty", "Lemon is sour".
/************************************************************* */
// Refactor the for() loop to be a while loop.
for(let i=0; i<10; i++) {
// console.log(" the value of i in the loop is : " + i);
}
//your code...
/************************************************************* */
//Multiply the sum of 30 added to two by 20. Divide the product by 10 raised to the power of 2
//use javascript to compute the value of the above statement. Each individual operation needs to be a function expression. run all the functions after defining them, and print the answer to the console.
//your code...
/************************************************************* */
//Determine whether the following values are "truthy" or "falsy". console.log() the value, whether the value is 'truthy' or 'falsy', along with your reasoning why using String interpolation values :
// ex : 3 is truthy, because it is a number, and numbers are type coerced as 'true' when performing logical (boolean) operations.
// 20
// 0
// "zero";
// const zero = 20;
// null
// "0"
// !""
// {}
// () => {console.log("hello TEKcamp!");
// 125
// undefined
// ""
/************************************************************* */
// Refactor the following code using a switch statement:
const day = "friday";
if(day === "monday") {
console.log("we got a long week ahead of us...");
} else if(day === "tuesday") {
console.log("tuesday's are still beterr than mondays, but LONG way to go still");
} else if (day === "wednesday") {
console.log("We are smack dab in the middle of the week");
} else if (day === "thursday") {
console.log("Thursday night... the mood is right");
} else if (day === "friday") {
console.log("TGIF. Friday truly is the best day of the week!")
} else {
console.log("It's a weekend!")
}
/************************************************************* */
// Refactor the following statements to use ternary expressions:
const age = 10;
if (age > 21) console.log("adult"); else {
console.log("minor");
}
if (age > 13 && age < 19) console.log('teen'); else {
console.log("not a teenager");
};
if (age > 65) console.log("retired"); else {
console.log("still working...");
}
/************************************************************* */
//Create an object literal representing yourself. Set it equal to a variable that appropriately describes the object. Include the following properties:
/*
-name
-age
-gender
-healthy ? (yes or no)
-hobbies
-profession
-education
-add a method on your object, entitled 'learn'. The learn method should print out the message : "[your name] is learning JavaScript". The learn method should print the value of the name property using the 'this' keyword.
-add another method on your object of any action you want to perform, using some property that exists on your object. Make sure to reference any properties on your objedct using the 'this' keyword.
*/
//your code...
/************************************************************* */
{
const year = 2021;
const nums = [1,2,3,4,5];
let sum = 0;
let i = 0;
const doubled = [];
//Refactor the following statements into expressions
// 1.
if(year > 2000 && year < 2100) {
console.log("welcome to the 21st century");
}
// 2.
for(let i=0; i<nums.length; i++) {
sum += nums[i];
}
console.log(sum);
// 3.
while(i < nums.length) {
doubled.push(nums[i]*2);
i++;
}
console.log(doubled);
}
/************************************************************* */
// Use array methods to solve the following problems.
const nums = [1,2,3,4,5];
// Square every number in the array. Store the squares in a new array.
//your code...
const fivePlus = [1,3,5,7,9,1,3,5,2,3,1,23,4,232,3,4,1,2,2,2,3,4,4,1,12,11,23,3,4,5];
//Remove all numbers that are less than 5. Store the results in a new array.
//your code...
// Create an array of 20 randomly generated integers. Calculate the sum of the elements in the array.
//your code...
const showNums = [12,22,33,44,55,66,77,88,99,101];
//Print out the value of each number divided by 2. There is no need to store the output in an array.
/************************************************************* */
/* Chess pieces have point values associated with them.
Pawn = 1, Rook = 5, Bishop = 3, Knight = 3, Queen = 9, King = N/A
Write a function that calculates the total point value of any given input list of Chess pieces.
ex : ['king','queen','pawn','pawn','pawn','bishop'] => chessCalc() => 15
If there are invalid chess pieces, discard those elements.
ex : ['iPhone','queen','pawn'] => chessCalc() => 10
['android'] => chessCalc() => null
*/
function chessCalc(pieces) {
//your code here
}
/************************************************************* */
const ones = [1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111];
//reverse the array, without modifying / `mutating` the ones array.
/************************************************************* */
//create a function called performer(cb) that takes in a callback function and runs that callback function. The function should return the output of the callback function.
function performer(cb) {
//code goes here
}
/************************************************************* */
// For the given list of developers :
const devs = [
{
name: 'Cameron',
age: 23,
gender: 'm',
"tech_stack" : ['html','css','js','React']
},
{
name: 'Liz',
age: 20,
gender: 'f',
"tech_stack" : ['java','spring-boot','MySql']
},
{
name: 'Chris',
age: 102,
gender: 'm',
"tech_stack" : ['react','express','python']
},
{
name: 'Rashid',
age: 27,
gender: 'm',
"tech_stack" : ['thymeleaf','postgres','js','Angular']
},
{
name: 'Annie',
age: 30,
gender: 'F',
"tech_stack" : ['html','scss','less','DynamoDB','GraphQL']
},
{
name: 'Dr. Patel',
age: 52,
gender: 'M',
"tech_stack" : null
},
{
name: 'Isaiah',
age: 48,
gender: 'M',
"tech_stack" : ['Java','','less','DynamoDB','GraphQL']
},
{
name: 'Saima',
age: 33,
gender: 'F',
"tech_stack" : ['MongoDB','Route53','Jenkins','Terraform','Kubernetes']
},
{
name: 'Omar',
age: 33,
gender: 'm',
"tech_stack" : ['c++']
},
{
name: 'Mariam',
age: 32,
gender: 'f',
"tech_stack" : null
},
];
/************************** */
// Find all devs older than 24
//your code here...
/************************** */
// Remove all people who are not developers (i.e. no tech stack)
//your code here...
/************************** */
// Calculate the total age of all the devs
//your code here...
/************************** */
// Find all female devs
//your code here...
/************************** */
// lowercase the genders of every dev
//your code here...
/************************** */
// Sort the developers by name
//your code here
/************************** */
// Sort the devs by age in descending order
//your code here
/************************** */
// Sort the male coders by age
//your code here
/************************** */
// For the list of devs, print out sentences including the name and tech stack of each dev, leaving out other information. Example output is provided below :
/*
Liz specializes in Java, Spring Boot, and MySql.
Chris specializes in React, Express, and Python.
Dr. Patel is not a developer.
*/
//your code here
/************************************************************* */
// Write a function to find the maximum numerical value of the given array. Get rid of any non numerical values. Convert the strings that are numbers to an actual number data type. ("one" => 1) ("1" => 1). Use array methods to perform this task.
const numbersMixed = [2,23,1,2,1,1,1,2,2.5,20,200,2000,,{k:"val"},20000,19999,1878,140,23,4,"sk",true,true,"true-dat","nice","one","two","three","3","tea",[]];
function maxNumber(numbers) {
//your code...
}
//After the numbers array has been cleaned up to only have numbers in it, Write a function that sorts the modified numbers array. Allow the function to sort the array in descending order as well.
function sortNums(numbers,desc=false) {
//your code...
};
/************************************************************* */
//Research a new feature of ES6+ and create an example of it's use case here. Be sure to write comments explaining what the feature is and why it is useful.
//your code...
/************************************************************* */
//Add an example of the 5 primary JavaScript data types to the given mapObj. The key is an example data type, and the value is the name of the data type. An object data type has already been set as the 1st key / val pair.
const mapObj = new Map();
mapObj.set({company : "TEKsystems"},"object");
console.log(mapObj.has({company : "TEKsystems"}));
//The above console.log() statmeent returns false. Write another console.log() statement explaining why this line of code prints false. Refactor the code `mapObj.set()`, so the code : `mapObj.has() returns true. The goal is to successfully check and see if {company : "TEKsystems"} exists in the mapObj.
//your code...
//loop through the mapObj and create a new array of only the data types, leaving out the example keys of the mapObj. Use array methods to do this. Example output : ['string',number','boolean',array','object']
/************************************************************* */
//Create 4 mathematical function expressions, add,subtract,multiply,divide. put them in an array, and create a doMath() function that randomly selects one of the mathematical operations whenever it is invoked. The doMath() function should print to the console the mathetmatical function that was carried out. The doMath() function should return the computed value of any operation performed.
// ex : 2,3 => doMath(2,3) => adding : 5
const operations = [];
function doMath(x,y) {};
//your code...
/************************************************************* */
//- Create a Higher Order Function called multiple(x) that takes a single parameter. This HOF should return another function fn(y) that accepts another single parameter y. This inner function should compute the product of it's parameter with the parameter passed into multiple. Use this returned "first-class" function to compute triples of any given number.
//your code...
//- Write an outer function called stockGain that has cost basis (basis) as a parameter; declare a variable called message that holds " is how much the stock has increased". Return an inner function with years (yrs) as a parameter and declare a variable for growth rate (r) of 5%. Console log your calculation.
//your code
// Once finished, declare a variable called futureValue that holds your stockGain function and enter any amount for the cost basis and a number for the number of years. Run the function returned by the higher order function to display the future value of the stock.
//your code...
// DO NOT DELETE THIS EXPORT
module.exports = {
tekCamp,
canVote
}
//*************************************** */