Skip to content
This repository was archived by the owner on May 29, 2023. It is now read-only.

Commit ed7b950

Browse files
author
Federico Vitale
committed
Beautify
1 parent 12c6818 commit ed7b950

File tree

2 files changed

+78
-62
lines changed

2 files changed

+78
-62
lines changed

src/challenges.js

+19-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @returns {Number} Rounded number
1616
*/
17-
module.exports.round = function(n, places = 0) {}
17+
module.exports.round = function (n, places = 0) {}
1818

1919

2020
/**
@@ -32,7 +32,7 @@ module.exports.round = function(n, places = 0) {}
3232
*
3333
* @returns {Array} Returns the merge of all arrays
3434
*/
35-
module.exports.arrayMerge = function(...arr) {}
35+
module.exports.arrayMerge = function (...arr) {}
3636

3737

3838
/**
@@ -51,7 +51,7 @@ module.exports.arrayMerge = function(...arr) {}
5151
*
5252
* @return {Number} The sum of all items in the array
5353
*/
54-
module.exports.arraySum = function(arr) {}
54+
module.exports.arraySum = function (arr) {}
5555

5656

5757
/**
@@ -70,7 +70,7 @@ module.exports.arraySum = function(arr) {}
7070
*
7171
* @returns {Object} The start object
7272
*/
73-
module.exports.objectForEach = function(obj, callback) {}
73+
module.exports.objectForEach = function (obj, callback) {}
7474

7575

7676
/**
@@ -88,7 +88,7 @@ module.exports.objectForEach = function(obj, callback) {}
8888
*
8989
* @returns {String} String reversed.
9090
*/
91-
module.exports.reverseString = function(str) {}
91+
module.exports.reverseString = function (str) {}
9292

9393

9494
/**
@@ -106,7 +106,7 @@ module.exports.reverseString = function(str) {}
106106
*
107107
* @returns {Boolean} Return true if is a palindrome.
108108
*/
109-
module.exports.isPalindrome = function(str) {}
109+
module.exports.isPalindrome = function (str) {}
110110

111111

112112
/**
@@ -125,7 +125,7 @@ module.exports.isPalindrome = function(str) {}
125125
*
126126
* @returns {Boolean} If `a` is multiple of `b` returns true
127127
*/
128-
module.exports.isMultipleOf = function(a, b) {}
128+
module.exports.isMultipleOf = function (a, b) {}
129129

130130

131131
/**
@@ -143,7 +143,7 @@ module.exports.isMultipleOf = function(a, b) {}
143143
*
144144
* @returns {String} Returns the longest word of `str`
145145
*/
146-
module.exports.longestWord = function(str) {}
146+
module.exports.longestWord = function (str) {}
147147

148148

149149
/**
@@ -161,7 +161,7 @@ module.exports.longestWord = function(str) {}
161161
*
162162
* @returns {String} Returns a capitalized string
163163
*/
164-
module.exports.capitalize = function(str) {}
164+
module.exports.capitalize = function (str) {}
165165

166166

167167

@@ -180,7 +180,7 @@ module.exports.capitalize = function(str) {}
180180
*
181181
* @returns {Number} Returns number of vowels in `str`
182182
*/
183-
module.exports.vowelCount = function(str) {}
183+
module.exports.vowelCount = function (str) {}
184184

185185

186186

@@ -199,7 +199,7 @@ module.exports.vowelCount = function(str) {}
199199
*
200200
* @returns {Number} Returns character most used in the string.
201201
*/
202-
module.exports.maxChar = function(str) {}
202+
module.exports.maxChar = function (str) {}
203203

204204

205205
/**
@@ -219,7 +219,11 @@ module.exports.maxChar = function(str) {}
219219
*
220220
* @returns {Array} Returns an array of numbers
221221
*/
222-
module.exports.fizzBuzz = function({n1 = 3, n2 = 5, max = 100} = {}) {}
222+
module.exports.fizzBuzz = function ({
223+
n1 = 3,
224+
n2 = 5,
225+
max = 100
226+
} = {}) {}
223227

224228

225229
/**
@@ -237,7 +241,7 @@ module.exports.fizzBuzz = function({n1 = 3, n2 = 5, max = 100} = {}) {}
237241
*
238242
* @returns {Number} Returns sum of all numbers from 0 to `counter`
239243
*/
240-
module.exports.simpleAdding = function(num) {}
244+
module.exports.simpleAdding = function (num) {}
241245

242246

243247
/**
@@ -260,7 +264,7 @@ module.exports.arrayToTree = function (...paths) {}
260264

261265

262266
/**
263-
* CHALLENGE 14: ARRAY TO TREE
267+
* CHALLENGE 15: ALPHABETICALLY SORT
264268
* @name alphabeticallySort
265269
* @description Write a function that can be used into an Array.sort() for sorting items alphabetically.
266270
* @author Nachiketha <[email protected]>
@@ -276,4 +280,4 @@ module.exports.arrayToTree = function (...paths) {}
276280
*
277281
* @returns {Boolean}
278282
*/
279-
module.exports.alphabeticallySort = function(a, b) {}
283+
module.exports.alphabeticallySort = function (a, b) {}

src/solutions.js

+59-47
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
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 = /[aAeEiIoOuU]/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
*/
350354
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+
}
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

Comments
 (0)