Skip to content

Commit f9bb681

Browse files
chore: apply prettier all files❤️
1 parent a7765dc commit f9bb681

File tree

13 files changed

+48
-156
lines changed

13 files changed

+48
-156
lines changed

convert-string-to-group/solution.js

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,26 @@ const solution = (optionRule) => {
66

77
const convert = (groupRule) => {
88
for (const delimiter of delimiters) {
9-
const regDelimiter = new RegExp(
10-
`[ ]*${delimiter}[ ]*`,
11-
);
9+
const regDelimiter = new RegExp(`[ ]*${delimiter}[ ]*`);
1210
if (!regDelimiter.test(groupRule)) {
1311
continue;
1412
}
1513
stack.push({
16-
[delimiter]: groupRule
17-
.split(regDelimiter)
18-
.map((rule) => {
19-
const option = Number(rule.replace(/\D/g, ''));
14+
[delimiter]: groupRule.split(regDelimiter).map((rule) => {
15+
const option = Number(rule.replace(/\D/g, ''));
2016

21-
return (
22-
(/^#\d+#$/.test(rule) && stack[option - 1]) ||
23-
option
24-
);
25-
}),
17+
return (/^#\d+#$/.test(rule) && stack[option - 1]) || option;
18+
}),
2619
});
2720
break;
2821
}
2922
};
3023

3124
while (groupPattern.test(currentRule)) {
32-
currentRule = currentRule.replace(
33-
groupPattern,
34-
(match) => {
35-
convert(match.substring(1, match.length - 1));
36-
return `#${stack.length}#`;
37-
},
38-
);
25+
currentRule = currentRule.replace(groupPattern, (match) => {
26+
convert(match.substring(1, match.length - 1));
27+
return `#${stack.length}#`;
28+
});
3929
}
4030

4131
convert(currentRule);
@@ -45,12 +35,6 @@ const solution = (optionRule) => {
4535

4636
(() => {
4737
console.log(
48-
JSON.stringify(
49-
solution(
50-
'{1069} AND ({1070} OR {1071} OR {1072}) AND {1244} AND ({1245} OR {1339})',
51-
),
52-
null,
53-
2,
54-
),
38+
JSON.stringify(solution('{1069} AND ({1070} OR {1071} OR {1072}) AND {1244} AND ({1245} OR {1339})'), null, 2),
5539
);
5640
})();

delete-overlapping-intervals/solution.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
const sortIntervals = ([aStart, aEnd], [bStart, bEnd]) =>
2-
aStart > bStart || (aStart === bStart && aEnd > bEnd)
3-
? 1
4-
: -1;
2+
aStart > bStart || (aStart === bStart && aEnd > bEnd) ? 1 : -1;
53

6-
const doIntersect = ([aStart, aEnd], [bStart, bEnd]) =>
7-
aStart <= bEnd && aEnd >= bStart;
4+
const doIntersect = ([aStart, aEnd], [bStart, bEnd]) => aStart <= bEnd && aEnd >= bStart;
85

9-
const combineIntervals = (
10-
[aStart, aEnd],
11-
[bStart, bEnd],
12-
) => [Math.min(aStart, bStart), Math.max(aEnd, bEnd)];
6+
const combineIntervals = ([aStart, aEnd], [bStart, bEnd]) => [Math.min(aStart, bStart), Math.max(aEnd, bEnd)];
137

148
const solution = (intervals) =>
159
intervals
1610
.sort(sortIntervals)
1711
.reduce(
1812
(merged, currentSeg) =>
1913
merged.some((seg) => doIntersect(seg, currentSeg))
20-
? merged.map((seg) =>
21-
doIntersect(seg, currentSeg)
22-
? combineIntervals(seg, currentSeg)
23-
: seg,
24-
)
14+
? merged.map((seg) => (doIntersect(seg, currentSeg) ? combineIntervals(seg, currentSeg) : seg))
2515
: [...merged, currentSeg],
2616
[],
2717
);

filling-all-the-missed-angle-brackets/solution.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ const solution = (angles) => {
44
missedAngles = missedAngles.replace(/<>/g, '');
55
}
66
const missedOpens = missedAngles.replace(/</g, '').length;
7-
const missedCloses = missedAngles.replace(
8-
/>/g,
9-
'',
10-
).length;
11-
return `${'<'.repeat(missedOpens)}${angles}${'>'.repeat(
12-
missedCloses,
13-
)}`;
7+
const missedCloses = missedAngles.replace(/>/g, '').length;
8+
return `${'<'.repeat(missedOpens)}${angles}${'>'.repeat(missedCloses)}`;
149
};
1510

1611
(() => {

finding-all-the-anagrams/solution.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@ const findAnagrams = (words) => {
2727
};
2828

2929
(() => {
30-
const words = [
31-
'eat',
32-
'ate',
33-
'tea',
34-
'monk',
35-
'konm',
36-
'nkom',
37-
'bbc',
38-
'cbb',
39-
'dell',
40-
'ledl',
41-
'llde',
42-
];
30+
const words = ['eat', 'ate', 'tea', 'monk', 'konm', 'nkom', 'bbc', 'cbb', 'dell', 'ledl', 'llde'];
4331
console.log(findAnagrams(words));
4432
})();

finding-the-maximum-depth-of-a-binary-tree/solution.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
const solution = (tree) => {
2-
const makeNode = (
3-
values,
4-
offset = 0,
5-
index = 0,
6-
depth = 0,
7-
) => {
8-
if (
9-
!values ||
10-
index >= values.length ||
11-
values[index] === -1
12-
) {
2+
const makeNode = (values, offset = 0, index = 0, depth = 0) => {
3+
if (!values || index >= values.length || values[index] === -1) {
134
return null;
145
}
156
const left = Math.pow(2, depth) + index + offset;
@@ -38,9 +29,7 @@ const solution = (tree) => {
3829

3930
(() => {
4031
const tree = [
41-
1, 2, 3, 4, -1, 5, 6, -1, -1, -1, -1, 7, 8, -1, 9, -1,
42-
-1, -1, -1, -1, -1, -1, -1, -1, -1, 10, -1, -1, -1, 11,
43-
-1,
32+
1, 2, 3, 4, -1, 5, 6, -1, -1, -1, -1, 7, 8, -1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, -1, -1, -1, 11, -1,
4433
];
4534
console.log(solution(tree));
4635
})();

fixing-setting-up-a-callback/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const solution = (messages) => {
1515
}
1616

1717
trigger() {
18-
this.messages.forEach((message) =>
19-
this.event(message),
20-
);
18+
this.messages.forEach((message) => this.event(message));
2119
}
2220
}
2321

fixing-setting-up-a-callback/solution.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const solution = (messages) => {
1010
}
1111

1212
trigger() {
13-
this.messages.forEach((message) =>
14-
this.event(message),
15-
);
13+
this.messages.forEach((message) => this.event(message));
1614
}
1715
}
1816

@@ -36,12 +34,5 @@ const solution = (messages) => {
3634
};
3735

3836
(() => {
39-
console.log(
40-
solution([
41-
'Hello~',
42-
'Can you hear me?',
43-
'Nice to meet you.',
44-
'This is a test message.',
45-
]),
46-
);
37+
console.log(solution(['Hello~', 'Can you hear me?', 'Nice to meet you.', 'This is a test message.']));
4738
})();

frequency-of-alphabet-letters/solution.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ function g(str) {
77
while (codeA <= codeZ) {
88
const letter = String.fromCharCode(codeA++);
99

10-
letterFrequencies[letter] = str.replace(
11-
new RegExp(`[^${letter}]`, 'gi'),
12-
'',
13-
).length;
10+
letterFrequencies[letter] = str.replace(new RegExp(`[^${letter}]`, 'gi'), '').length;
1411
}
1512

1613
return letterFrequencies;

getting-the-distinct-transactions/solution.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ const solution = (transactions, taxRate) => {
1414

1515
const distinctTransactions = new Set(transactions);
1616

17-
Array.from(distinctTransactions).map(
18-
computeTotal(taxRate),
19-
);
17+
Array.from(distinctTransactions).map(computeTotal(taxRate));
2018

2119
return numCalls;
2220
};

replacing-characters/solution.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ function f(str) {
88
const reAlphabets = /[A-Za-z]/g;
99

1010
const fnReplacer = (substr) => {
11-
const offset =
12-
substr.toUpperCase().charCodeAt(0) - codeA;
13-
return String.fromCharCode(
14-
substr.charCodeAt(0) + 25 - 2 * offset,
15-
);
11+
const offset = substr.toUpperCase().charCodeAt(0) - codeA;
12+
return String.fromCharCode(substr.charCodeAt(0) + 25 - 2 * offset);
1613
};
1714

1815
return str.replace(reAlphabets, fnReplacer);
@@ -28,7 +25,5 @@ function solution(str) {
2825
(() => {
2926
solution('acp123!@#');
3027

31-
solution(
32-
'Errors in strategy cannot be correct through tactical maneuvers',
33-
);
28+
solution('Errors in strategy cannot be correct through tactical maneuvers');
3429
})();

0 commit comments

Comments
 (0)