14
14
*
15
15
* @returns {Number } Rounded number
16
16
*/
17
- module . exports . round = function ( n , places = 0 ) {
17
+ module . exports . round = function ( n , places = 0 ) {
18
18
places = Math . pow ( 10 , places )
19
19
20
20
return Math . floor ( n * places ) / places ;
@@ -36,7 +36,7 @@ module.exports.round = function(n, places = 0) {
36
36
*
37
37
* @returns {Array } Returns the merge of all arrays
38
38
*/
39
- module . exports . arrayMerge = function ( ...arr ) {
39
+ module . exports . arrayMerge = function ( ...arr ) {
40
40
return arr . reduce ( ( a , b ) => [ ...a , ...b ] ) ;
41
41
}
42
42
@@ -57,8 +57,8 @@ module.exports.arrayMerge = function(...arr) {
57
57
*
58
58
* @return {Number } The sum of all items in the array
59
59
*/
60
- module . exports . arraySum = function ( arr ) {
61
- return arr . reduce ( ( a , b ) => a + b ) ;
60
+ module . exports . arraySum = function ( arr ) {
61
+ return arr . reduce ( ( a , b ) => a + b ) ;
62
62
}
63
63
64
64
@@ -78,7 +78,7 @@ module.exports.arraySum = function(arr) {
78
78
*
79
79
* @returns {Object } The start object
80
80
*/
81
- module . exports . objectForEach = function ( obj , callback ) {
81
+ module . exports . objectForEach = function ( obj , callback ) {
82
82
Object . keys ( obj ) . forEach ( key => callback ( key , obj [ key ] ) ) ;
83
83
84
84
return obj ;
@@ -100,7 +100,7 @@ module.exports.objectForEach = function(obj, callback) {
100
100
*
101
101
* @returns {String } String reversed.
102
102
*/
103
- module . exports . reverseString = function ( str ) {
103
+ module . exports . reverseString = function ( str ) {
104
104
return str . split ( '' ) . reverse ( ) . join ( '' )
105
105
}
106
106
@@ -120,7 +120,7 @@ module.exports.reverseString = function(str) {
120
120
*
121
121
* @returns {Boolean } Return true if is a palindrome.
122
122
*/
123
- module . exports . isPalindrome = function ( str ) {
123
+ module . exports . isPalindrome = function ( str ) {
124
124
return str . split ( '' ) . reverse ( ) . join ( '' ) === str ;
125
125
}
126
126
@@ -141,7 +141,7 @@ module.exports.isPalindrome = function(str) {
141
141
*
142
142
* @returns {Boolean } If `a` is multiple of `b` returns true
143
143
*/
144
- module . exports . isMultipleOf = function ( a , b ) {
144
+ module . exports . isMultipleOf = function ( a , b ) {
145
145
return a % b === 0 ;
146
146
}
147
147
@@ -161,7 +161,7 @@ module.exports.isMultipleOf = function(a, b) {
161
161
*
162
162
* @returns {String } Returns the longest word of `str`
163
163
*/
164
- module . exports . longestWord = function ( str ) {
164
+ module . exports . longestWord = function ( str ) {
165
165
var words = str . trim ( ) . replace ( / \W / g, ' ' ) . trim ( ) . split ( / \s + / ) ;
166
166
167
167
words = words . sort ( ( a , b ) => {
@@ -187,7 +187,7 @@ module.exports.longestWord = function(str) {
187
187
*
188
188
* @returns {String } Returns a capitalized string
189
189
*/
190
- module . exports . capitalize = function ( str ) {
190
+ module . exports . capitalize = function ( str ) {
191
191
var words = str . trim ( ) . split ( / \s + / g)
192
192
return words . map ( word => {
193
193
return word [ 0 ] . toUpperCase ( ) + word . substr ( 1 , word . length )
@@ -211,7 +211,7 @@ module.exports.capitalize = function(str) {
211
211
*
212
212
* @returns {Number } Returns number of vowels in `str`
213
213
*/
214
- module . exports . vowelCount = function ( str ) {
214
+ module . exports . vowelCount = function ( str ) {
215
215
let isVowel = / [ a A e E i I o O u U ] / g
216
216
return str . split ( '' ) . filter ( letter => {
217
217
return isVowel . test ( letter )
@@ -235,23 +235,23 @@ module.exports.vowelCount = function(str) {
235
235
*
236
236
* @returns {Number } Returns character most used in the string.
237
237
*/
238
- module . exports . maxChar = function ( str ) {
238
+ module . exports . maxChar = function ( str ) {
239
239
let charMap = { } ;
240
240
let charCount = 0 ;
241
241
let charMostUsed = '' ;
242
242
243
- for ( var i = 0 ; i < str . split ( '' ) . length ; i ++ ) {
243
+ for ( var i = 0 ; i < str . split ( '' ) . length ; i ++ ) {
244
244
var letter = str . split ( '' ) [ i ] ;
245
245
246
- if ( charMap [ letter ] ) {
246
+ if ( charMap [ letter ] ) {
247
247
charMap [ letter ] ++
248
248
} else {
249
249
charMap [ letter ] = 1
250
250
}
251
251
}
252
252
253
253
for ( char in charMap ) {
254
- if ( charMap [ char ] > charCount ) {
254
+ if ( charMap [ char ] > charCount ) {
255
255
charCount = charMap [ char ]
256
256
charMostUsed = char ;
257
257
}
@@ -281,20 +281,24 @@ module.exports.maxChar = function(str) {
281
281
*
282
282
* @returns {Array } Returns an array of numbers
283
283
*/
284
- module . exports . fizzBuzz = function ( { n1 = 3 , n2 = 5 , max = 100 } = { } ) {
284
+ module . exports . fizzBuzz = function ( {
285
+ n1 = 3 ,
286
+ n2 = 5 ,
287
+ max = 100
288
+ } = { } ) {
285
289
var numbers = [ ] ;
286
- for ( let i = 0 ; i <= max ; i ++ ) {
290
+ for ( let i = 0 ; i <= max ; i ++ ) {
287
291
let char = '' ;
288
292
289
- if ( i % n1 === 0 ) {
293
+ if ( i % n1 === 0 ) {
290
294
char += 'Foo' ;
291
295
}
292
296
293
- if ( i % n2 === 0 ) {
297
+ if ( i % n2 === 0 ) {
294
298
char += 'Bar' ;
295
299
}
296
300
297
- numbers . push ( char || i ) ;
301
+ numbers . push ( char || i ) ;
298
302
}
299
303
300
304
return numbers
@@ -316,18 +320,18 @@ module.exports.fizzBuzz = function({n1 = 3, n2 = 5, max = 100} = {}) {
316
320
*
317
321
* @returns {Number } Returns sum of all numbers from 0 to `counter`
318
322
*/
319
- module . exports . simpleAdding = function ( num ) {
320
- var numbers = [ ] ;
323
+ module . exports . simpleAdding = function ( num ) {
324
+ var numbers = [ ] ;
321
325
322
326
num = Math . abs ( num )
323
327
324
- if ( num === 1 ) return 1 ;
328
+ if ( num === 1 ) return 1 ;
325
329
326
- for ( var i = 0 ; i <= num ; i ++ ) {
327
- numbers . push ( i )
328
- }
330
+ for ( var i = 0 ; i <= num ; i ++ ) {
331
+ numbers . push ( i )
332
+ }
329
333
330
- return numbers . reduce ( ( a , b ) => a + b ) ;
334
+ return numbers . reduce ( ( a , b ) => a + b ) ;
331
335
}
332
336
333
337
@@ -348,26 +352,34 @@ module.exports.simpleAdding = function(num) {
348
352
* @returns {Array } Returns the tree generated from `paths`
349
353
*/
350
354
module . exports . arrayToTree = function ( ...paths ) {
351
- var result = [ ] , tmp = { result }
352
-
353
- paths . forEach ( function ( path ) {
354
- path . reduce ( function ( r , name , i ) {
355
- if ( ! r [ name ] ) {
356
- var o = { name } , children = [ ]
357
-
358
- r [ name ] = { result : children }
359
-
360
- if ( path [ i + 1 ] ) {
361
- o . children = children
362
- }
355
+ var result = [ ] ,
356
+ tmp = {
357
+ result
358
+ }
363
359
364
- r . result . push ( o )
365
- }
366
- return r [ name ]
367
- } , tmp )
368
- } )
360
+ paths . forEach ( function ( path ) {
361
+ path . reduce ( function ( r , name , i ) {
362
+ if ( ! r [ name ] ) {
363
+ var o = {
364
+ name
365
+ } ,
366
+ children = [ ]
367
+
368
+ r [ name ] = {
369
+ result : children
370
+ }
371
+
372
+ if ( path [ i + 1 ] ) {
373
+ o . children = children
374
+ }
375
+
376
+ r . result . push ( o )
377
+ }
378
+ return r [ name ]
379
+ } , tmp )
380
+ } )
369
381
370
- return result ;
382
+ return result ;
371
383
}
372
384
373
385
@@ -388,6 +400,6 @@ module.exports.arrayToTree = function (...paths) {
388
400
*
389
401
* @returns {Boolean }
390
402
*/
391
- module . exports . alphabeticallySort = function ( a , b ) {
392
- return a . localeCompare ( b )
403
+ module . exports . alphabeticallySort = function ( a , b ) {
404
+ return a . localeCompare ( b )
393
405
}
0 commit comments