-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvancedHW.js
More file actions
278 lines (239 loc) · 8.71 KB
/
advancedHW.js
File metadata and controls
278 lines (239 loc) · 8.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
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
// JS Basics
/*
Create a variable called test and assign a string value to it.
*/
let test = "hello";
/*
Create a variable called sum and assign to it the result of the sum between the numbers 10 and 20.
*/
let sum = 10+20;
/*
Create a variable called random and assign to it a random number between 0 and 20 (it should be randomly created at each execution).
*/
let random =Math.floor(Math.random()*20)
console.log(random);
/*
Create a variable called me and assign to it an object containing the following information: name = your name, surname = your surname, age = your age.
*/
/*
Write a piece of code for programmatically removing the age property from the previously create object.
*/
/*
Write a piece of code for programmatically adding to the me object you defined before an array called skills, containing the programming languages you know right now.
*/
/*
Write a piece of code for programmatically removing the last skill from the skills array inside the me object.
*/
// JS Functions
/*
Write a function called dice; it should randomize an integer number between 1 and 6.
*/
/*
Write a function called whoIsBigger which receives 2 numbers as parameters and returns the biggest one.
*/
/*
Write a function called splitMe which receives a string as a parameter and returns an array with every word in that string.
Ex.: splitMe("I love coding") => returns ["I", "Love", "Coding"]
*/
/*
Write a function called deleteOne which receives a string and a boolean as parameters.
If the boolean value is true it should return the string without the first letter, otherwise it should remove the last one from it.
*/
/*
Write a function called onlyLetters which receives a string as a parameter and returns it removing all the digits.
Ex.: onlyLetters("I have 4 dogs") => returns "I have dogs"
*/
/*
Write a function called isThisAnEmail which receives a string as a parameter and returns true if the string is a valid email address.
*/
/*
Write a function called whatDayIsIt that should return the current day of the week.
*/
/*
Write a function called rollTheDices which receives a number as a parameter.
It should invoke the dice() function defined in Ex1 the specified amount of times,
and return an object containing a sum property holding the sum of all values extracted
and a values array containing the single values of the dicerolls themselves.
Example: RollTheDices(3) => returns {
sum: 10
values: [3, 3, 4]
}
*/
/*
Write a function called howManyDays which receives a date as a parameter and returns the number of days passed since that date.
*/
/*
Write a function called isTodayMyBirthday which should return true if today's your birthday, false otherwise.
*/
// JS Arrays & Objects
// NOTE: the movies array used in some exercises is defined at the end of this file
/* 11
Write a function called deleteProp which receives an object and a string as parameters,
and returns the given object after deleting its property named as the given string.
*/
/* 12
Write a function called oldestMovie which finds the oldest movie in the provided movies array.
*/
/* 13
Write a function called countMovies which returns the number of movies contained in the provided movies array.
*/
/* 14
Write a function called onlyTheTitles which creates an array with just the titles of the movies contained in the provided movies array.
*/
/* 15
Write a function called onlyInThisMillennium which returns only the movies produced in this millennium from the provided movies array.
*/
/* 16
Write a function called getMovieById which receives an id as a parameter and returns the movie with the given id from the provided movies array.
*/
/* 17
Write a function called sumAllTheYears which returns the sum of all the years in which the movies in the provided movies array have been produced.
*/
/* 18
Write a function called searchByTitle which receives a string as a parameter and returns all the movies in the provided movies array which contain that string in the title.
*/
/* 19
Write a function called searchAndDivide which receives a string as a parameter and returns an object;
this object should contain an array called match, made by all the movies from the provided movies array which contain the given string in the title,
and another array unmatch with all the remaining ones.
*/
/* 20
Write a function called "removeIndex" which receives a number as a parameter and returns the provided movies array without the element in the given position.
*/
// [EXTRAS] JS Advanced
/* 21
Create a function called "halfTree" which receives a number as a parameter and builds an "*" half tree with the given height.
Example:
halfTree(3)
*
**
***
*/
/* 22
Create a function called "tree" which receives a number as a parameter and builds an "*" tree with the given height.
Example:
tree(3)
*
***
*****
*/
/* 23
Create a function called "isItPrime" that receives a number as a parameter and returns true if the given number is a prime number.
*/
/*
*/
/* This movies array is used throughout the exercises. You're not supposed to alter it. */
const movies = [
{
Title: "The Lord of the Rings: The Fellowship of the Ring",
Year: "2001",
imdbID: "tt0120737",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BN2EyZjM3NzUtNWUzMi00MTgxLWI0NTctMzY4M2VlOTdjZWRiXkEyXkFqcGdeQXVyNDUzOTQ5MjY@._V1_SX300.jpg",
},
{
Title: "The Lord of the Rings: The Return of the King",
Year: "2003",
imdbID: "tt0167260",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BNzA5ZDNlZWMtM2NhNS00NDJjLTk4NDItYTRmY2EwMWZlMTY3XkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_SX300.jpg",
},
{
Title: "The Lord of the Rings: The Two Towers",
Year: "2002",
imdbID: "tt0167261",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BNGE5MzIyNTAtNWFlMC00NDA2LWJiMjItMjc4Yjg1OWM5NzhhXkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_SX300.jpg",
},
{
Title: "Lord of War",
Year: "2005",
imdbID: "tt0399295",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BMTYzZWE3MDAtZjZkMi00MzhlLTlhZDUtNmI2Zjg3OWVlZWI0XkEyXkFqcGdeQXVyNDk3NzU2MTQ@._V1_SX300.jpg",
},
{
Title: "Lords of Dogtown",
Year: "2005",
imdbID: "tt0355702",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BNDBhNGJlOTAtM2ExNi00NmEzLWFmZTQtYTZhYTRlNjJjODhmXkEyXkFqcGdeQXVyNDk3NzU2MTQ@._V1_SX300.jpg",
},
{
Title: "The Lord of the Rings",
Year: "1978",
imdbID: "tt0077869",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BOGMyNWJhZmYtNGQxYi00Y2ZjLWJmNjktNTgzZWJjOTg4YjM3L2ltYWdlXkEyXkFqcGdeQXVyNTAyODkwOQ@@._V1_SX300.jpg",
},
{
Title: "Lord of the Flies",
Year: "1990",
imdbID: "tt0100054",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BOTI2NTQyODk0M15BMl5BanBnXkFtZTcwNTQ3NDk0NA@@._V1_SX300.jpg",
},
{
Title: "The Lords of Salem",
Year: "2012",
imdbID: "tt1731697",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BMjA2NTc5Njc4MV5BMl5BanBnXkFtZTcwNTYzMTcwOQ@@._V1_SX300.jpg",
},
{
Title: "Greystoke: The Legend of Tarzan, Lord of the Apes",
Year: "1984",
imdbID: "tt0087365",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BMTM5MzcwOTg4MF5BMl5BanBnXkFtZTgwOTQwMzQxMDE@._V1_SX300.jpg",
},
{
Title: "Lord of the Flies",
Year: "1963",
imdbID: "tt0057261",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BOGEwYTlhMTgtODBlNC00ZjgzLTk1ZmEtNmNkMTEwYTZiM2Y0XkEyXkFqcGdeQXVyMzU4Nzk4MDI@._V1_SX300.jpg",
},
{
Title: "The Avengers",
Year: "2012",
imdbID: "tt0848228",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BNDYxNjQyMjAtNTdiOS00NGYwLWFmNTAtNThmYjU5ZGI2YTI1XkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_SX300.jpg",
},
{
Title: "Avengers: Infinity War",
Year: "2018",
imdbID: "tt4154756",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BMjMxNjY2MDU1OV5BMl5BanBnXkFtZTgwNzY1MTUwNTM@._V1_SX300.jpg",
},
{
Title: "Avengers: Age of Ultron",
Year: "2015",
imdbID: "tt2395427",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BMTM4OGJmNWMtOTM4Ni00NTE3LTg3MDItZmQxYjc4N2JhNmUxXkEyXkFqcGdeQXVyNTgzMDMzMTg@._V1_SX300.jpg",
},
{
Title: "Avengers: Endgame",
Year: "2019",
imdbID: "tt4154796",
Type: "movie",
Poster:
"https://m.media-amazon.com/images/M/MV5BMTc5MDE2ODcwNV5BMl5BanBnXkFtZTgwMzI2NzQ2NzM@._V1_SX300.jpg",
},
];