1414 *
1515 * @returns {Number } Rounded number
1616 */
17- module . exports . round = function ( n , places = 0 ) {
17+ module . exports . round = function ( n , places = 0 ) {
1818 places = Math . pow ( 10 , places )
1919
2020 return Math . floor ( n * places ) / places ;
@@ -36,7 +36,7 @@ module.exports.round = function(n, places = 0) {
3636 *
3737 * @returns {Array } Returns the merge of all arrays
3838 */
39- module . exports . arrayMerge = function ( ...arr ) {
39+ module . exports . arrayMerge = function ( ...arr ) {
4040 return arr . reduce ( ( a , b ) => [ ...a , ...b ] ) ;
4141}
4242
@@ -57,8 +57,8 @@ module.exports.arrayMerge = function(...arr) {
5757 *
5858 * @return {Number } The sum of all items in the array
5959 */
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 ) ;
6262}
6363
6464
@@ -78,7 +78,7 @@ module.exports.arraySum = function(arr) {
7878 *
7979 * @returns {Object } The start object
8080 */
81- module . exports . objectForEach = function ( obj , callback ) {
81+ module . exports . objectForEach = function ( obj , callback ) {
8282 Object . keys ( obj ) . forEach ( key => callback ( key , obj [ key ] ) ) ;
8383
8484 return obj ;
@@ -100,7 +100,7 @@ module.exports.objectForEach = function(obj, callback) {
100100 *
101101 * @returns {String } String reversed.
102102 */
103- module . exports . reverseString = function ( str ) {
103+ module . exports . reverseString = function ( str ) {
104104 return str . split ( '' ) . reverse ( ) . join ( '' )
105105}
106106
@@ -120,7 +120,7 @@ module.exports.reverseString = function(str) {
120120 *
121121 * @returns {Boolean } Return true if is a palindrome.
122122 */
123- module . exports . isPalindrome = function ( str ) {
123+ module . exports . isPalindrome = function ( str ) {
124124 return str . split ( '' ) . reverse ( ) . join ( '' ) === str ;
125125}
126126
@@ -141,7 +141,7 @@ module.exports.isPalindrome = function(str) {
141141 *
142142 * @returns {Boolean } If `a` is multiple of `b` returns true
143143 */
144- module . exports . isMultipleOf = function ( a , b ) {
144+ module . exports . isMultipleOf = function ( a , b ) {
145145 return a % b === 0 ;
146146}
147147
@@ -161,7 +161,7 @@ module.exports.isMultipleOf = function(a, b) {
161161 *
162162 * @returns {String } Returns the longest word of `str`
163163 */
164- module . exports . longestWord = function ( str ) {
164+ module . exports . longestWord = function ( str ) {
165165 var words = str . trim ( ) . replace ( / \W / g, ' ' ) . trim ( ) . split ( / \s + / ) ;
166166
167167 words = words . sort ( ( a , b ) => {
@@ -187,7 +187,7 @@ module.exports.longestWord = function(str) {
187187 *
188188 * @returns {String } Returns a capitalized string
189189 */
190- module . exports . capitalize = function ( str ) {
190+ module . exports . capitalize = function ( str ) {
191191 var words = str . trim ( ) . split ( / \s + / g)
192192 return words . map ( word => {
193193 return word [ 0 ] . toUpperCase ( ) + word . substr ( 1 , word . length )
@@ -211,7 +211,7 @@ module.exports.capitalize = function(str) {
211211 *
212212 * @returns {Number } Returns number of vowels in `str`
213213 */
214- module . exports . vowelCount = function ( str ) {
214+ module . exports . vowelCount = function ( str ) {
215215 let isVowel = / [ a A e E i I o O u U ] / g
216216 return str . split ( '' ) . filter ( letter => {
217217 return isVowel . test ( letter )
@@ -235,23 +235,23 @@ module.exports.vowelCount = function(str) {
235235 *
236236 * @returns {Number } Returns character most used in the string.
237237 */
238- module . exports . maxChar = function ( str ) {
238+ module . exports . maxChar = function ( str ) {
239239 let charMap = { } ;
240240 let charCount = 0 ;
241241 let charMostUsed = '' ;
242242
243- for ( var i = 0 ; i < str . split ( '' ) . length ; i ++ ) {
243+ for ( var i = 0 ; i < str . split ( '' ) . length ; i ++ ) {
244244 var letter = str . split ( '' ) [ i ] ;
245245
246- if ( charMap [ letter ] ) {
246+ if ( charMap [ letter ] ) {
247247 charMap [ letter ] ++
248248 } else {
249249 charMap [ letter ] = 1
250250 }
251251 }
252252
253253 for ( char in charMap ) {
254- if ( charMap [ char ] > charCount ) {
254+ if ( charMap [ char ] > charCount ) {
255255 charCount = charMap [ char ]
256256 charMostUsed = char ;
257257 }
@@ -281,20 +281,24 @@ module.exports.maxChar = function(str) {
281281 *
282282 * @returns {Array } Returns an array of numbers
283283 */
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+ } = { } ) {
285289 var numbers = [ ] ;
286- for ( let i = 0 ; i <= max ; i ++ ) {
290+ for ( let i = 0 ; i <= max ; i ++ ) {
287291 let char = '' ;
288292
289- if ( i % n1 === 0 ) {
293+ if ( i % n1 === 0 ) {
290294 char += 'Foo' ;
291295 }
292296
293- if ( i % n2 === 0 ) {
297+ if ( i % n2 === 0 ) {
294298 char += 'Bar' ;
295299 }
296300
297- numbers . push ( char || i ) ;
301+ numbers . push ( char || i ) ;
298302 }
299303
300304 return numbers
@@ -316,18 +320,18 @@ module.exports.fizzBuzz = function({n1 = 3, n2 = 5, max = 100} = {}) {
316320 *
317321 * @returns {Number } Returns sum of all numbers from 0 to `counter`
318322 */
319- module . exports . simpleAdding = function ( num ) {
320- var numbers = [ ] ;
323+ module . exports . simpleAdding = function ( num ) {
324+ var numbers = [ ] ;
321325
322326 num = Math . abs ( num )
323327
324- if ( num === 1 ) return 1 ;
328+ if ( num === 1 ) return 1 ;
325329
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+ }
329333
330- return numbers . reduce ( ( a , b ) => a + b ) ;
334+ return numbers . reduce ( ( a , b ) => a + b ) ;
331335}
332336
333337
@@ -348,26 +352,34 @@ module.exports.simpleAdding = function(num) {
348352 * @returns {Array } Returns the tree generated from `paths`
349353 */
350354module . 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+ }
363359
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+ } )
369381
370- return result ;
382+ return result ;
371383}
372384
373385
@@ -388,6 +400,6 @@ module.exports.arrayToTree = function (...paths) {
388400 *
389401 * @returns {Boolean }
390402 */
391- module . exports . alphabeticallySort = function ( a , b ) {
392- return a . localeCompare ( b )
403+ module . exports . alphabeticallySort = function ( a , b ) {
404+ return a . localeCompare ( b )
393405}
0 commit comments