This repository has been archived by the owner on May 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
challenges.js
315 lines (281 loc) 路 8.02 KB
/
challenges.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
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
/**
* CHALLENGE 1: ROUND NUMBER
* @name round
* @description Write a function that round a number (`n`) to given decimal places.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* round(Math.PI, 2) // => 3.14
*
*
* @param {Number} n The number to be rounded
* @param {Number} places Decimal places
*
* @returns {Number} Rounded number
*/
module.exports.round = function (n, places = 0) {}
/**
* CHALLENGE 2: MERGE MULTIPLE ARRAYS
* @name arrayMerge
* @description Write a function that merges multiple given arrays.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* ArrayMerge([1, 2], ['a', 'b']) //=> [1, 2, 'a', 'b']
*
*
* @param {Array} arr Arrays to merge
*
* @returns {Array} Returns the merge of all arrays
*/
module.exports.arrayMerge = function (...arr) {}
/**
* CHALLENGE 3: SUM CONTENT OF AN ARRAY
*
* @name arraySum
* @description Write a function to sum the content of an array
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* arraySum([10, 10, 10]) //=> 30
*
*
* @param {Array} arr Array to sum
*
* @return {Number} The sum of all items in the array
*/
module.exports.arraySum = function (arr) {}
/**
* CHALLENGE 4: OBJECT FOREACH
* @name objectForEach
* @description ForEach function that works with Objects.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* objectForEach({ a:1, b:2 }, (key, value) => console.log(key, value)) //=> { a:1, b:2 }
*
*
* @param {Object} obj Main Object
* @param {Function} callback Function callback
*
* @returns {Object} The start object
*/
module.exports.objectForEach = function (obj, callback) {}
/**
* CHALLENGE 5: REVERSE STRING
* @name reverseString
* @description A function that reverse a string.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* reverseString('hello') //=> 'ollah'
*
*
* @param {String} str String to be reversed.
*
* @returns {String} String reversed.
*/
module.exports.reverseString = function (str) {}
/**
* CHALLENGE 6: CHECK PALINDROME
* @name isPalindrome
* @description A function that checks if a word is a palindrome.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* isPalindrome('racecar') //=> true
*
*
* @param {String} str String to be checked for palindrome.
*
* @returns {Boolean} Return true if is a palindrome.
*/
module.exports.isPalindrome = function (str) {}
/**
* CHALLENGE 7: IS MULTIPLE OF
* @name isMultipleOf
* @description A function that checks if a number is multiple of another number.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* isMultipleOf(3, 15) //=> true
*
*
* @param {Number} a Number to be checked for multiple of `b`
* @param {Number} b
*
* @returns {Boolean} If `a` is multiple of `b` returns true
*/
module.exports.isMultipleOf = function (a, b) {}
/**
* CHALLENGE 8: GET THE LONGEST WORD
* @name longestWord
* @description A function that returns the longest word of a sentence.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* longestWord('short loooong l0000ng') //=> 'loooong'
*
*
* @param {String} str The string to be checked
*
* @returns {String} Returns the longest word of `str`
*/
module.exports.longestWord = function (str) {}
/**
* CHALLENGE 9: CAPITALIZE
* @name capitalize
* @description A function that capitalize each word in a sentence.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* capitalize('hello world') //=> 'Hello World'
*
*
* @param {String} str The string to be capitalized
*
* @returns {String} Returns a capitalized string
*/
module.exports.capitalize = function (str) {}
/**
* CHALLENGE 10: VOWEL COUNT
* @name vowelCount
* @description A function that count vowel in a sentence.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* vowelCount('fox') //=> 1
*
*
* @param {String} str The string to be checked
*
* @returns {Number} Returns number of vowels in `str`
*/
module.exports.vowelCount = function (str) {}
/**
* CHALLENGE 11: MAX CHAR
* @name maxChar
* @description Get the most used char in a sentence.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* maxChar('hello') //=> l
*
*
* @param {String} str The string to be checked
*
* @returns {Number} Returns character most used in the string.
*/
module.exports.maxChar = function (str) {}
/**
* CHALLENGE 12: FIZZ BUZZ
* @name fizzBuzz
* @description Fizz Buzz game, generate number from 0 to `max` and if the number is multiple of `n1` print "Fizz", if the number is multiple of `n2` print "Buzz", if is multiple of both print "FizzBuzz" else print the number.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example
* fizzBuzz() //=> [0, 1, 2, Fizz, 4, Buzz ...etc]
*
*
* @param {Number} n1 Fizz number
* @param {Number} n2 Buzz number
* @param {Number} max Length of the array
*
* @returns {Array} Returns an array of numbers
*/
module.exports.fizzBuzz = function ({
n1 = 3,
n2 = 5,
max = 100
} = {}) {}
/**
* CHALLENGE 13: SIMPLE ADDING
* @name simpleAdding
* @description Write a function that sums all numbers from 0 to the given number.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
*
* @example Usage:
* simpleAdding(3) //=> 6
*
*
* @param {Number} num Counter
*
* @returns {Number} Returns sum of all numbers from 0 to `counter`
*/
module.exports.simpleAdding = function (num) {}
/**
* CHALLENGE 14: ARRAY TO TREE
* @name arrayToTree
* @description Transform an array into a tree like object.
* @author Nenad Vracar (http://nenadvracar.com)
*
* @see https://stackoverflow.com/questions/48951551/what-is-the-most-efficient-way-to-transform-an-array-of-array-of-string-to-a-tre
*
* @example Usage:
* arrayToTree(['folder', 'subfolder', 'file.txt']) //=> [{name: 'folder', children: [ { name: 'subfolder', children: [ {name: 'file.txt'} ]} ]}]
*
*
* @param {Array} paths Array of the items to convert
*
* @returns {Array} Returns the tree generated from `paths`
*/
module.exports.arrayToTree = function (...paths) {}
/**
* CHALLENGE 15: ALPHABETICALLY SORT
* @name alphabeticallySort
* @description Write a function that can be used into an Array.sort() for sorting items alphabetically.
* @author Nachiketha <nachikethashu[at]gmail.com>
*
* @see https://stackoverflow.com/questions/6712034/sort-array-by-firstname-alphabetically-in-javascript
*
* @example Usage:
* ['Italy', 'Canada', 'Australia'].sort(alphabeticallySort) //=> ['Australia', 'Canada', 'Italy']
*
*
* @param {String} a First argument of the `.sort` function
* @param {String} b Second argument of the `.sort` function
*
* @returns {Boolean}
*/
module.exports.alphabeticallySort = function (a, b) {}
/**
* CHALLENGE 16: FIRST RECURRING CHARACTER
* @name firstRecurringCharacter
* @description Write a function that returns the first recurring character in a string or null if no recursion.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
* @example Usage:
* firstRecurringChar('federico') // => 'e'
*
* @param {String} str String to analyze
*
* @returns {String} or {Null}
*/
module.exports.firstRecurringChar = function(str) {}
/**
* CHALLENGE 17: OBJECT MERGE
* @name objectMerge
* @description Write a function that returns an object that includes all given objects.
* @author Federico Vitale <fedevitale99[at]gmail.com>
*
* @example Usage:
* objectMerge({ a: 'b' }, { c: 'd' }) // => { a: 'b', c: 'd' }
*
* @param {Array} objects - An array of objects
*
* @returns {Object}
*/
module.exports.objectMerge = function(...objects) {}