Skip to content

Commit 373804d

Browse files
style: Prettier
Add Prettier and format code
1 parent 3b986ee commit 373804d

File tree

42 files changed

+179
-202
lines changed

Some content is hidden

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

42 files changed

+179
-202
lines changed

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# codewars
22

3-
![](https://www.codewars.com/users/marcobiedermann/badges/micro)
3+
![](https://www.codewars.com/users/marcobiedermann/badges/micro)

jest.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
// collectCoverageFrom: null,
2525

2626
// The directory where Jest should output its coverage files
27-
coverageDirectory: "coverage",
27+
coverageDirectory: 'coverage',
2828

2929
// An array of regexp pattern strings used to skip coverage collection
3030
// coveragePathIgnorePatterns: [
@@ -91,7 +91,7 @@ module.exports = {
9191
// notifyMode: "failure-change",
9292

9393
// A preset that is used as a base for Jest's configuration
94-
preset: "ts-jest",
94+
preset: 'ts-jest',
9595

9696
// Run tests from one or more projects
9797
// projects: null,
@@ -132,7 +132,7 @@ module.exports = {
132132
// snapshotSerializers: [],
133133

134134
// The test environment that will be used for testing
135-
testEnvironment: "node"
135+
testEnvironment: 'node',
136136

137137
// Options that will be passed to the testEnvironment
138138
// testEnvironmentOptions: {},
+5-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
import comp from ".";
1+
import comp from '.';
22

3-
describe("comp", () => {
4-
it("should check if both array are the same with the same multiplicities", () => {
3+
describe('comp', () => {
4+
it('should check if both array are the same with the same multiplicities', () => {
55
expect(
66
comp(
77
[121, 144, 19, 161, 19, 144, 19, 11],
8-
[
9-
11 * 11,
10-
121 * 121,
11-
144 * 144,
12-
19 * 19,
13-
161 * 161,
14-
19 * 19,
15-
144 * 144,
16-
19 * 19
17-
]
18-
)
8+
[11 * 11, 121 * 121, 144 * 144, 19 * 19, 161 * 161, 19 * 19, 144 * 144, 19 * 19],
9+
),
1910
).toEqual(true);
2011
});
2112
});

kata/6-kyu/christmas-tree/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ function christmasTree(height: number): string {
99

1010
for (let column = 0; column < columns; column += 1) {
1111
if (midpoint - row <= column && midpoint + row >= column) {
12-
level.push("*");
12+
level.push('*');
1313
} else {
14-
level.push(" ");
14+
level.push(' ');
1515
}
1616
}
1717

18-
tree.push(level.join(""));
18+
tree.push(level.join(''));
1919
}
2020

21-
return tree.join("\n");
21+
return tree.join('\n');
2222
}
2323

2424
export default christmasTree;
+6-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import createPhoneNumber from ".";
1+
import createPhoneNumber from '.';
22

3-
describe("createPhoneNumber", () => {
4-
it("should format array of numbers to phone number", () => {
5-
expect(createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])).toEqual(
6-
"(123) 456-7890"
7-
);
8-
expect(createPhoneNumber([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])).toEqual(
9-
"(111) 111-1111"
10-
);
11-
expect(createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])).toEqual(
12-
"(123) 456-7890"
13-
);
3+
describe('createPhoneNumber', () => {
4+
it('should format array of numbers to phone number', () => {
5+
expect(createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])).toEqual('(123) 456-7890');
6+
expect(createPhoneNumber([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])).toEqual('(111) 111-1111');
7+
expect(createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])).toEqual('(123) 456-7890');
148
});
159
});
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function createPhoneNumber(numbers: number[]): string {
2-
return numbers.join("").replace(/(\d{3})(\d{3})(\d{4})/g, "($1) $2-$3");
2+
return numbers.join('').replace(/(\d{3})(\d{3})(\d{4})/g, '($1) $2-$3');
33
}
44

55
export default createPhoneNumber;

kata/6-kyu/equal-sides-of-an-array/index.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
function sumArr(arr: number[]): number {
2-
return arr.reduce(
3-
(accumulator, currentValue) => accumulator + currentValue,
4-
0
5-
);
2+
return arr.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
63
}
74

85
function findEvenIndex(arr: number[]): number {
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import list from ".";
1+
import list from '.';
22

3-
describe("list", () => {
4-
it("should separate names by comma, except for the last two", () => {
3+
describe('list', () => {
4+
it('should separate names by comma, except for the last two', () => {
55
expect(
66
list([
7-
{ name: "Bart" },
8-
{ name: "Lisa" },
9-
{ name: "Maggie" },
10-
{ name: "Homer" },
11-
{ name: "Marge" }
12-
])
13-
).toEqual("Bart, Lisa, Maggie, Homer & Marge");
14-
expect(
15-
list([{ name: "Bart" }, { name: "Lisa" }, { name: "Maggie" }])
16-
).toEqual("Bart, Lisa & Maggie");
17-
expect(list([{ name: "Bart" }, { name: "Lisa" }])).toEqual("Bart & Lisa");
18-
expect(list([{ name: "Bart" }])).toEqual("Bart");
19-
expect(list([])).toEqual("");
7+
{ name: 'Bart' },
8+
{ name: 'Lisa' },
9+
{ name: 'Maggie' },
10+
{ name: 'Homer' },
11+
{ name: 'Marge' },
12+
]),
13+
).toEqual('Bart, Lisa, Maggie, Homer & Marge');
14+
expect(list([{ name: 'Bart' }, { name: 'Lisa' }, { name: 'Maggie' }])).toEqual(
15+
'Bart, Lisa & Maggie',
16+
);
17+
expect(list([{ name: 'Bart' }, { name: 'Lisa' }])).toEqual('Bart & Lisa');
18+
expect(list([{ name: 'Bart' }])).toEqual('Bart');
19+
expect(list([])).toEqual('');
2020
});
2121
});

kata/6-kyu/format-a-string-of-names-like-Bart-Lisa-and-Maggie/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ interface Person {
55
function list(names: Person[]): string {
66
return names
77
.map(({ name }) => name)
8-
.join(", ")
9-
.replace(/(.*), (.*)/, "$1 & $2");
8+
.join(', ')
9+
.replace(/(.*), (.*)/, '$1 & $2');
1010
}
1111

1212
export default list;

kata/6-kyu/playing-with-digits/index.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
function digPow(n: number, p: number): number {
22
const digits = n
33
.toString()
4-
.split("")
4+
.split('')
55
.map(Number);
66

77
const sum = digits.reduce(
8-
(accumulator, currentValue, index) =>
9-
accumulator + currentValue ** (index + p),
10-
0
8+
(accumulator, currentValue, index) => accumulator + currentValue ** (index + p),
9+
0,
1110
);
1211

1312
return sum % n ? -1 : sum / n;

kata/6-kyu/rectangle-into-squares/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import sqInRect from ".";
1+
import sqInRect from '.';
22

3-
describe("sqInRect", () => {
4-
it("should return number of squares in rect", () => {
3+
describe('sqInRect', () => {
4+
it('should return number of squares in rect', () => {
55
expect(sqInRect(5, 5)).toEqual(null);
66
expect(sqInRect(5, 3)).toEqual([3, 2, 1, 1]);
77
expect(sqInRect(3, 5)).toEqual([3, 2, 1, 1]);

kata/7-kyu/disemvowel-trolls/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function disemvowel(str: string): string {
2-
return str.replace(/[aeiou]/gi, "");
2+
return str.replace(/[aeiou]/gi, '');
33
}
44

55
export default disemvowel;

kata/7-kyu/is-this-a-triangle/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import isTriangle from ".";
1+
import isTriangle from '.';
22

3-
describe("isTriangle", () => {
4-
it("should check if triangle is valid", () => {
3+
describe('isTriangle', () => {
4+
it('should check if triangle is valid', () => {
55
expect(isTriangle(1, 2, 2)).toEqual(true);
66
expect(isTriangle(7, 2, 2)).toEqual(false);
77
});
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import number from ".";
1+
import number from '.';
22

3-
describe("number", () => {
4-
it("return number of people sitting in bus after last bus station", () => {
3+
describe('number', () => {
4+
it('return number of people sitting in bus after last bus station', () => {
55
expect(
66
number([
77
[10, 0],
88
[3, 5],
9-
[5, 8]
10-
])
9+
[5, 8],
10+
]),
1111
).toEqual(5);
1212
expect(
1313
number([
@@ -16,8 +16,8 @@ describe("number", () => {
1616
[4, 10],
1717
[12, 2],
1818
[6, 1],
19-
[7, 10]
20-
])
19+
[7, 10],
20+
]),
2121
).toEqual(17);
2222
expect(
2323
number([
@@ -26,8 +26,8 @@ describe("number", () => {
2626
[4, 8],
2727
[12, 2],
2828
[6, 1],
29-
[7, 8]
30-
])
29+
[7, 8],
30+
]),
3131
).toEqual(21);
3232
});
3333
});

kata/7-kyu/ones-and-zeros/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import binaryArrayToNumber from ".";
1+
import binaryArrayToNumber from '.';
22

3-
describe("binaryArrayToNumber", () => {
4-
it("should convert binary value in array to integer", () => {
3+
describe('binaryArrayToNumber', () => {
4+
it('should convert binary value in array to integer', () => {
55
expect(binaryArrayToNumber([0, 0, 0, 1])).toEqual(1);
66
expect(binaryArrayToNumber([0, 0, 1, 0])).toEqual(2);
77
expect(binaryArrayToNumber([1, 1, 1, 1])).toEqual(15);

kata/7-kyu/ones-and-zeros/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function binaryArrayToNumber(arr: number[]): number {
2-
return parseInt(arr.join(""), 2);
2+
return parseInt(arr.join(''), 2);
33
}
44

55
export default binaryArrayToNumber;
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
import validatePIN from ".";
1+
import validatePIN from '.';
22

3-
describe("validatePIN", function() {
4-
it("should return False for pins with length other than 4 or 6", () => {
5-
expect(validatePIN("1")).toEqual(false);
6-
expect(validatePIN("12")).toEqual(false);
7-
expect(validatePIN("123")).toEqual(false);
8-
expect(validatePIN("12345")).toEqual(false);
9-
expect(validatePIN("1234567")).toEqual(false);
10-
expect(validatePIN("-1234")).toEqual(false);
11-
expect(validatePIN("1.234")).toEqual(false);
12-
expect(validatePIN("-1.234")).toEqual(false);
13-
expect(validatePIN("00000000")).toEqual(false);
3+
describe('validatePIN', function() {
4+
it('should return False for pins with length other than 4 or 6', () => {
5+
expect(validatePIN('1')).toEqual(false);
6+
expect(validatePIN('12')).toEqual(false);
7+
expect(validatePIN('123')).toEqual(false);
8+
expect(validatePIN('12345')).toEqual(false);
9+
expect(validatePIN('1234567')).toEqual(false);
10+
expect(validatePIN('-1234')).toEqual(false);
11+
expect(validatePIN('1.234')).toEqual(false);
12+
expect(validatePIN('-1.234')).toEqual(false);
13+
expect(validatePIN('00000000')).toEqual(false);
1414
});
1515

16-
it("should return False for pins which contain characters other than digits", () => {
17-
expect(validatePIN("a234")).toEqual(false);
18-
expect(validatePIN(".234")).toEqual(false);
16+
it('should return False for pins which contain characters other than digits', () => {
17+
expect(validatePIN('a234')).toEqual(false);
18+
expect(validatePIN('.234')).toEqual(false);
1919
});
2020

21-
it("should return True for valid pins", () => {
22-
expect(validatePIN("1234")).toEqual(true);
23-
expect(validatePIN("0000")).toEqual(true);
24-
expect(validatePIN("1111")).toEqual(true);
25-
expect(validatePIN("123456")).toEqual(true);
26-
expect(validatePIN("098765")).toEqual(true);
27-
expect(validatePIN("000000")).toEqual(true);
28-
expect(validatePIN("123456")).toEqual(true);
29-
expect(validatePIN("090909")).toEqual(true);
21+
it('should return True for valid pins', () => {
22+
expect(validatePIN('1234')).toEqual(true);
23+
expect(validatePIN('0000')).toEqual(true);
24+
expect(validatePIN('1111')).toEqual(true);
25+
expect(validatePIN('123456')).toEqual(true);
26+
expect(validatePIN('098765')).toEqual(true);
27+
expect(validatePIN('000000')).toEqual(true);
28+
expect(validatePIN('123456')).toEqual(true);
29+
expect(validatePIN('090909')).toEqual(true);
3030
});
3131
});

kata/7-kyu/remove-the-minimum/index.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import removeSmallest from ".";
1+
import removeSmallest from '.';
22

3-
describe("removeSmallest", function() {
4-
it("works for the examples", function() {
3+
describe('removeSmallest', function() {
4+
it('works for the examples', function() {
55
expect(removeSmallest([1, 2, 3, 4, 5])).toEqual([2, 3, 4, 5]);
66
expect(removeSmallest([5, 3, 2, 1, 4])).toEqual([5, 3, 2, 4]);
77
expect(removeSmallest([2, 2, 1, 2, 1])).toEqual([2, 2, 2, 1]);
88
expect(removeSmallest([])).toEqual([]);
99
});
1010

11-
it("returns [] if the list has only one element", function() {
11+
it('returns [] if the list has only one element', function() {
1212
for (let i = 0; i < 10; ++i) {
1313
let x = ~~(Math.random() * 400);
1414
expect(removeSmallest([x])).toEqual([]);
@@ -19,7 +19,7 @@ describe("removeSmallest", function() {
1919
return Array.from({ length: length }, () => ~~(Math.random() * 400));
2020
}
2121

22-
it("returns a list that misses only one element", function() {
22+
it('returns a list that misses only one element', function() {
2323
for (let i = 0; i < 10; ++i) {
2424
let arr = randomArray(~~(Math.random() * 10) + 1);
2525
let l = arr.length;
+8-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import reverseWords from ".";
1+
import reverseWords from '.';
22

3-
describe("reverseWords", () => {
4-
it("should reverse each word in string", () => {
5-
expect(
6-
reverseWords("The quick brown fox jumps over the lazy dog.")
7-
).toEqual("ehT kciuq nworb xof spmuj revo eht yzal .god");
8-
expect(reverseWords("apple")).toEqual("elppa");
9-
expect(reverseWords("a b c d")).toEqual("a b c d");
10-
expect(reverseWords("double spaced words")).toEqual(
11-
"elbuod decaps sdrow"
3+
describe('reverseWords', () => {
4+
it('should reverse each word in string', () => {
5+
expect(reverseWords('The quick brown fox jumps over the lazy dog.')).toEqual(
6+
'ehT kciuq nworb xof spmuj revo eht yzal .god',
127
);
8+
expect(reverseWords('apple')).toEqual('elppa');
9+
expect(reverseWords('a b c d')).toEqual('a b c d');
10+
expect(reverseWords('double spaced words')).toEqual('elbuod decaps sdrow');
1311
});
1412
});

0 commit comments

Comments
 (0)