Skip to content

Commit 4402e00

Browse files
committed
chore: improve formatting
1 parent dfadf29 commit 4402e00

File tree

81 files changed

+560
-616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+560
-616
lines changed

7kyu-1/findTheCapitals.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
// Instructions
2-
// Write a function that takes a single string (word) as argument.
2+
// Write a function that takes a single string (word) as argument.
33
// The function must return an ordered list containing the indexes of all capital letters in the string.
44

55
// Example (Input --> Output)
66
// "CodEWaRs" --> [0,3,4,6]
77

88
var capitals = function (word) {
9-
10-
let result = []
11-
12-
for(let i = 0; i < word.length; i++){
13-
let letters = word[i]
14-
if(/[A-Z]/.test(letters)){
15-
let indexes = word.indexOf(letters);
16-
result.push(indexes)
17-
}
18-
}
19-
return result
20-
21-
};
9+
let result = [];
10+
11+
for (let i = 0; i < word.length; i++) {
12+
let letters = word[i];
13+
if (/[A-Z]/.test(letters)) {
14+
let indexes = word.indexOf(letters);
15+
result.push(indexes);
16+
}
17+
}
18+
return result;
19+
};

7kyu-1/findTheStrayNumber.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// You are given an odd-length array of integers,
1+
// You are given an odd-length array of integers,
22
// in which all of them are the same, except for one single number.
33

4-
// Complete the method which accepts such an array,
4+
// Complete the method which accepts such an array,
55
// and returns that single different number.
66

77
// The input array will always be valid! (odd-length >= 3)
@@ -11,21 +11,19 @@
1111
// [17, 17, 3, 17, 17, 17, 17] ==> 3
1212

1313
function stray(numbers) {
14-
let numCounts = {};
15-
16-
17-
for (let num of numbers) {
18-
if (numCounts[num]) {
19-
numCounts[num] += 1;
20-
} else {
21-
numCounts[num] = 1;
22-
}
14+
let numCounts = {};
15+
16+
for (let num of numbers) {
17+
if (numCounts[num]) {
18+
numCounts[num] += 1;
19+
} else {
20+
numCounts[num] = 1;
2321
}
24-
25-
26-
for (let num in numCounts) {
27-
if (numCounts[num] === 1) {
28-
return parseInt(num);
29-
}
22+
}
23+
24+
for (let num in numCounts) {
25+
if (numCounts[num] === 1) {
26+
return parseInt(num);
3027
}
31-
}
28+
}
29+
}

7kyu-1/friendOrFoe.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Make a program that filters a list of
22
// strings and returns a list with only your friends name in it.
33

4-
// If a name has exactly 4 letters in it, you can be sure
4+
// If a name has exactly 4 letters in it, you can be sure
55
// that it has to be a friend of yours! Otherwise, you can be sure he's not...
66

77
// Ex: Input = ["Ryan", "Kieran", "Jason", "Yous"], Output = ["Ryan", "Yous"]
@@ -11,8 +11,6 @@
1111
// friend ["Ryan", "Kieran", "Mark"] `shouldBe` ["Ryan", "Mark"]
1212
// Note: keep the original order of the names in the output.
1313

14-
function friend(friends){
15-
16-
return friends.filter(x => x.length === 4);
17-
18-
}
14+
function friend(friends) {
15+
return friends.filter((x) => x.length === 4);
16+
}

7kyu-1/geTheMiddleCharacter.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// You are going to be given a word. Your job is to return the middle character of the word.
2-
// If the word's length is odd, return the middle character. If the word's length is even,
2+
// If the word's length is odd, return the middle character. If the word's length is even,
33
// return the middle 2 characters.
44

55
// #Examples:
@@ -21,20 +21,18 @@
2121

2222
// The middle character(s) of the word represented as a string.
2323

24-
function getMiddle(s){
25-
26-
str = s;
27-
let position;
28-
let length;
29-
30-
if(str.length % 2 == 0) {
31-
position = str.length / 2 - 1;
32-
length = 2;
33-
} else {
34-
position = str.length / 2;
35-
length = 1;
36-
}
37-
38-
return str.substring(position, position + length)
39-
40-
}
24+
function getMiddle(s) {
25+
str = s;
26+
let position;
27+
let length;
28+
29+
if (str.length % 2 == 0) {
30+
position = str.length / 2 - 1;
31+
length = 2;
32+
} else {
33+
position = str.length / 2;
34+
length = 1;
35+
}
36+
37+
return str.substring(position, position + length);
38+
}

7kyu-1/moneyMoneyMoney.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
// Mr. Scrooge has a sum of money 'P' that he wants to invest.
2-
// Before he does, he wants to know how many years 'Y' this sum 'P'
1+
// Mr. Scrooge has a sum of money 'P' that he wants to invest.
2+
// Before he does, he wants to know how many years 'Y' this sum 'P'
33
// has to be kept in the bank in order for it to amount to a desired sum of money 'D'.
44

5-
// The sum is kept for 'Y' years in the bank where interest 'I' is paid yearly.
5+
// The sum is kept for 'Y' years in the bank where interest 'I' is paid yearly.
66
// After paying taxes 'T' for the year the new sum is re-invested.
77

88
// Note to Tax: not the invested principal is taxed, but only the year's accrued interest
99

1010
// Example:
1111

12-
// Let P be the Principal = 1000.00
13-
// Let I be the Interest Rate = 0.05
14-
// Let T be the Tax Rate = 0.18
12+
// Let P be the Principal = 1000.00
13+
// Let I be the Interest Rate = 0.05
14+
// Let T be the Tax Rate = 0.18
1515
// Let D be the Desired Sum = 1100.00
1616

17-
1817
// After 1st Year -->
1918
// P = 1041.00
2019
// After 2nd Year -->
@@ -23,23 +22,22 @@
2322
// P = 1128.30
2423
// Thus Mr. Scrooge has to wait for 3 years for the initial principal to amount to the desired sum.
2524

26-
// Your task is to complete the method provided and return the number of years 'Y'
25+
// Your task is to complete the method provided and return the number of years 'Y'
2726
// as a whole in order for Mr. Scrooge to get the desired sum.
2827

29-
// Assumption: Assume that Desired Principal 'D' is always greater than the initial principal.
30-
// However it is best to take into consideration that if Desired Principal 'D' is equal to Principal
28+
// Assumption: Assume that Desired Principal 'D' is always greater than the initial principal.
29+
// However it is best to take into consideration that if Desired Principal 'D' is equal to Principal
3130
// 'P' this should return 0 Years.
3231

3332
function calculateYears(principal, interestRate, taxRate, desiredSum) {
34-
let years = 0;
35-
36-
while (principal < desiredSum) {
37-
const interest = principal * interestRate;
38-
const taxes = interest * taxRate;
39-
principal += interest - taxes;
40-
years++;
41-
}
42-
43-
return years;
33+
let years = 0;
34+
35+
while (principal < desiredSum) {
36+
const interest = principal * interestRate;
37+
const taxes = interest * taxRate;
38+
principal += interest - taxes;
39+
years++;
4440
}
4541

42+
return years;
43+
}

7kyu-1/numberOfPeopleInTheBus.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// There is a bus moving in the city which takes and drops some people at each bus stop.
22

3-
// You are provided with a list (or array) of integer pairs. Elements of each pair represent the number
3+
// You are provided with a list (or array) of integer pairs. Elements of each pair represent the number
44
// of people that get on the bus (the first item) and the number of people that get off the bus (the second item) at a bus stop.
55

66
// Your task is to return the number of people who are still on the bus after the last bus stop (after the last array).
7-
// Even though it is the last bus stop, the bus might not be empty and some people might still be inside the bus,
7+
// Even though it is the last bus stop, the bus might not be empty and some people might still be inside the bus,
88
// they are probably sleeping there :D
99

1010
// Take a look on the test cases.
@@ -19,22 +19,21 @@
1919
// assert.strictEqual(number([[3,0],[9,1],[4,8],[12,2],[6,1],[7,8]]),21);
2020
// assert.strictEqual(number([[0,0]]),0);
2121

22-
var number = function(busStops){
23-
let totalPeople = 0;
24-
for (let i=0; i<busStops.length; i++) {
25-
totalPeople += busStops[i][0];
26-
totalPeople -= busStops[i][1];
27-
}
28-
return totalPeople;
22+
var number = function (busStops) {
23+
let totalPeople = 0;
24+
for (let i = 0; i < busStops.length; i++) {
25+
totalPeople += busStops[i][0];
26+
totalPeople -= busStops[i][1];
2927
}
28+
return totalPeople;
29+
};
3030

31+
// var number = function(busStops){
32+
// let peopleOnBus = 0;
3133

32-
// var number = function(busStops){
33-
// let peopleOnBus = 0;
34-
35-
// for (const [on, off] of busStops) {
36-
// peopleOnBus += on - off;
37-
// }
38-
39-
// return Math.max(peopleOnBus, 0);
40-
// }
34+
// for (const [on, off] of busStops) {
35+
// peopleOnBus += on - off;
36+
// }
37+
38+
// return Math.max(peopleOnBus, 0);
39+
// }

7kyu-1/printerErrors.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// In a factory a printer prints labels for boxes. For one kind of boxes the printer
1+
// In a factory a printer prints labels for boxes. For one kind of boxes the printer
22
// has to use colors which, for the sake of simplicity, are named with letters from a to m.
33

44
// The colors used by the printer are recorded in a control string. For example a "good"
5-
// control string would be aaabbbbhaijjjm meaning that the printer used three times color a,
5+
// control string would be aaabbbbhaijjjm meaning that the printer used three times color a,
66
// four times color b, one time color h then one time color a...
77

8-
// Sometimes there are problems: lack of colors, technical malfunction and a "bad"
8+
// Sometimes there are problems: lack of colors, technical malfunction and a "bad"
99
// control string is produced e.g. aaaxbbbbyyhwawiwjjjwwm with letters not from a to m.
1010

11-
// You have to write a function printer_error which given a string will return the
11+
// You have to write a function printer_error which given a string will return the
1212
// error rate of the printer as a string representing a rational whose numerator is the number of errors
1313
// and the denominator the length of the control string. Don't reduce this fraction to a simpler expression.
1414

@@ -22,14 +22,14 @@
2222
// printer_error(s) => "8/22"
2323

2424
function printerError(s) {
25-
const validRange = /[a-m]/;
26-
let errorCount = 0;
27-
28-
for (let i = 0; i < s.length; i++) {
29-
if (!validRange.test(s[i])) {
30-
errorCount++;
31-
}
25+
const validRange = /[a-m]/;
26+
let errorCount = 0;
27+
28+
for (let i = 0; i < s.length; i++) {
29+
if (!validRange.test(s[i])) {
30+
errorCount++;
3231
}
33-
34-
return `${errorCount}/${s.length}`;
35-
}
32+
}
33+
34+
return `${errorCount}/${s.length}`;
35+
}

7kyu-1/shortestWord.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
// String will never be empty and you do not need to account for different data types.
44

55
function findShort(s) {
6+
const words = s.split(" ");
67

7-
const words = s.split(' ');
8-
9-
let shortestLength = Infinity;
10-
11-
12-
for (const word of words) {
13-
const wordLength = word.length;
14-
if (wordLength < shortestLength) {
15-
shortestLength = wordLength;
16-
}
8+
let shortestLength = Infinity;
9+
10+
for (const word of words) {
11+
const wordLength = word.length;
12+
if (wordLength < shortestLength) {
13+
shortestLength = wordLength;
1714
}
18-
15+
}
16+
1917
return shortestLength;
20-
}
18+
}

7kyu-1/smallEnough.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// You will be given an array and a limit value. You must check that all values in
1+
// You will be given an array and a limit value. You must check that all values in
22
// the array are below or equal to the limit value. If they are, return true. Else, return false.
33

44
// You can assume all values in the array are numbers.
55

6-
function smallEnough(a, limit){
7-
8-
return a.every((num) => num <= limit)
9-
10-
}
6+
function smallEnough(a, limit) {
7+
return a.every((num) => num <= limit);
8+
}

7kyu-1/sortArrayByStringLength.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Write a function that takes an array of strings as an argument and returns
1+
// Write a function that takes an array of strings as an argument and returns
22
// a sorted array containing the same strings, ordered from shortest to longest.
33

44
// For example, if this array were passed as an argument:
@@ -12,6 +12,6 @@
1212
// All of the strings in the array passed to your function will be different lengths,
1313
// so you will not have to decide how to order multiple strings of the same length.
1414

15-
function sortByLength (array) {
16-
return array.sort((a, b) => a.length - b.length);
17-
};
15+
function sortByLength(array) {
16+
return array.sort((a, b) => a.length - b.length);
17+
}

0 commit comments

Comments
 (0)