forked from mago0oxx/javascript-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercises.js
More file actions
199 lines (169 loc) · 5.58 KB
/
exercises.js
File metadata and controls
199 lines (169 loc) · 5.58 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
// FUNCTIONS SECTION
function minutesSeconds(minutes) {
// Write a function that receives an integer as an argument (minutes)
// and return the convertion to seconds
// ex:
// minutesSeconds(5) => 300
// minutesSeconds(3) => 180
// Code:
}
function sameLength(string1, string2) {
// Write a function that receives two strings as a arguments (string1, string2)
// returns true if the strings have the same length, return false if not
// ex:
// sameLength('Cintia', 'Rafael') => true
// sameLength('Vanesa', 'Chayanne') => false
// Code:
}
function sayHello(name, age) {
// Write a function that receives a string (name) and an integer (age)
// return a string including that name and the age
// ex:
// sayHello('Laureano', 22) => 'Hi, my name is Laureano. I am 22 years old.'
// sayHello('Ramiro', 28) => 'Hi, my name is Ramiro. I am 28 years old.'
// INTENTEN HACERLO CON BACKTICKS
// Code:
}
function arraySum(array) {
// Write a function that receives an array of integers as an argument (array)
// and return the sum of all the elements
// ex:
// arraySum([5, 2, 4, 5]) => 16
// arraySum([3, 4, 1]) => 8
// Code:
// NO HAGAN TRAMPA, NO VALE USAR REDUCE
}
function findInArray(array, number) {
// Write a function that receives an array of integers and a number as arguments (array, number)
// return true if the number is in the array, return false if not
// ex:
// findInArray([5, 2, 4, 5], 2) => true
// findInArray([3, 4, 1], 2) => false
// Code:
}
function average(array) {
// Write a function that receives an array of integers as an argument (array)
// and return the average of them
// ex:
// average([1,2,3]) => 2
// average([10, 20, 3]) => 11
// Code:
}
function randomNumbers(number) {
// Write a function that receives an integer (between 1 and 99) as an argument (number)
// return an array of random integers (do not repeat numbers) with "number" elements inside
// ex:
// randomNumbers(5); => [23, 11, 4, 76, 30]
// randomNumbers(3); => [3, 54, 18]
// Code:
}
function triangleArea(base, height) {
// Write a function that receives a number for the height (height) and another for the base (base)
// return the area of a triangle with that sizes
// ex:
// triangleArea(5, 10); => 25
// triangleArea(3, 20); => 30
}
function isVowel(letter) {
// Write a function that receives a letter (letter) as an argument
// if the letter is a vowel, should return "Is vowel", if not it should return "Is not vowel"
// In case the argument is not a string or if it's a string with more than one letter
// return "Incorrect data"
// ex:
// isVowel('a') => 'Is vowel';
// isVowel(6) => 'Is not vowel';
}
function findTheWord(string) {
// Write a function that receives a string (string) and returns true if it finds the word "viseven" inside.
// if not, returns false.
// ex:
// findTheWord('welcome to viseven') => true;
// findTheWord('hi, my name is Agustin') => false;
// Code:
}
function createObject(name, surname, age, city) {
// Write a function that receives four arguments (name, surname, age and city)
// return an object containing that arguments
// ex:
// createObject('Carolina', 'Ulla', 27, 'Cordoba') => {
// name: 'Carolina',
// surname: 'Ulla',
// age: 27,
// city: 'Cordoba'
// }
// Code:
}
function highestRating(arr) {
// Write a function that receives an array (arr) with information of players as an argument
// return a string with the name of the player with highest rating and the rating
// ex:
// let players = [
// { name: 'Cintia', rating: 2000 },
// { name: 'Rafael', rating: 3000 },
// { name: 'Agustin', rating: 1200 },
// { name: 'Soledad', rating: 9999 },
// ]
//
// highestRating(players) => 'The best player is Soledad, with 9999 points.'
// Code:
}
function objectKeys(obj) {
// Write a function that receives an object (obj) as an argument
// return an array with a list of all the properties in the object
// ex:
// let employee = {
// name: 'Cinthia',
// age: 32,
// city: 'CABA',
// company: 'Viseven'
// }
//
// objectKeys(employee) => ['name', 'age', 'city', 'company']
// Code:
}
function showRespectToRiquelme(arr) {
// Write a function that receives an array (arr) of objects as an argument
// look for Riquelme and add him a property showing your respect
// return the same arr with the change
// ex:
// let people = [
// { name: 'Cintia' },
// { name: 'Rafael' },
// { name: 'Agustin' },
// { name: 'Soledad'},
// { name: 'Riquelme'},
// { name: 'Anatolii'},
// { name: 'Camila'},
// { name: 'Simon'},
// ]
//
// showRespectToRiquelme(people) => [
// { name: 'Cintia' },
// { name: 'Rafael' },
// { name: 'Agustin' },
// { name: 'Soledad'},
// { name: 'Riquelme', respect: 'You are the best' },
// { name: 'Anatolii'},
// { name: 'Camila'},
// { name: 'Simon'},
// ]
// Code:
}
// ---------------------------------------------------------------------------------------------------------------
// do not touch
module.exports = {
minutesSeconds,
sameLength,
sayHello,
arraySum,
findInArray,
average,
findTheWord,
randomNumbers,
triangleArea,
isVowel,
createObject,
highestRating,
objectKeys,
showRespectToRiquelme
};