Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc2d7aa6

Browse files
authored
Add and run prettier (#234)
* chore: add `prettier`* style: run `prettier`* chore: check formatting in CI
1 parentc5b12db commitc2d7aa6

File tree

205 files changed

+11151
-10755
lines changed

Some content is hidden

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

205 files changed

+11151
-10755
lines changed

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ jobs:
1616
node-version:"18.x"
1717
-run:npm ci
1818
-run:npm test
19+
-run:npm run check-style

‎.gitpod.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
tasks:
22
-init:|
33
npm install && npm test
4-
5-

‎.prettierignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.github
2+
*.md

‎.prettierrc‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"endOfLine": "lf",
5+
"insertPragma": false,
6+
"printWidth": 80,
7+
"proseWrap": "preserve",
8+
"quoteProps": "as-needed",
9+
"requirePragma": false,
10+
"semi": false,
11+
"singleQuote": true,
12+
"tabWidth": 2,
13+
"trailingComma": "none",
14+
"useTabs": false
15+
}

‎babel.config.js‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports={
2-
presets:[
3-
['@babel/preset-env',{targets:{node:'current'}}],
4-
'@babel/preset-typescript'
5-
]
6-
};
7-
2+
presets:[
3+
['@babel/preset-env',{targets:{node:'current'}}],
4+
'@babel/preset-typescript'
5+
]
6+
}

‎backtracking/all_combinations_of_size_k.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* and repeat the same process for the next number.
1111
*/
1212
exportfunctiongenerateCombinations(n:number,k:number):number[][]{
13-
constcombinationsAcc:number[][]=[];
14-
constcurrentCombination:number[]=[];
13+
constcombinationsAcc:number[][]=[]
14+
constcurrentCombination:number[]=[]
1515

1616
functiongenerateAllCombos(
1717
n:number,
@@ -20,19 +20,19 @@ export function generateCombinations(n: number, k: number): number[][] {
2020
):number[][]{
2121
if(k===0){
2222
if(currentCombination.length>0){
23-
combinationsAcc.push(currentCombination.slice());
23+
combinationsAcc.push(currentCombination.slice())
2424
}
25-
returncombinationsAcc;
25+
returncombinationsAcc
2626
}
2727

28-
constendCursor=n-k+2;
28+
constendCursor=n-k+2
2929
for(leti=startCursor;i<endCursor;i++){
30-
currentCombination.push(i);
31-
generateAllCombos(n,k-1,i+1);
32-
currentCombination.pop();
30+
currentCombination.push(i)
31+
generateAllCombos(n,k-1,i+1)
32+
currentCombination.pop()
3333
}
34-
returncombinationsAcc;
34+
returncombinationsAcc
3535
}
3636

37-
returngenerateAllCombos(n,k,1);
37+
returngenerateAllCombos(n,k,1)
3838
}

‎backtracking/generateparentheses.ts‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,30 @@
66
*/
77

88
constgenerateParentheses=(n:number):string[]=>{
9-
constresult:string[]=[];
9+
constresult:string[]=[]
1010

11-
constsolve=(chars:string,openParentheses:number,closedParentheses:number)=>{
11+
constsolve=(
12+
chars:string,
13+
openParentheses:number,
14+
closedParentheses:number
15+
)=>{
1216
if(openParentheses===n&&closedParentheses===n){
13-
result.push(chars);
14-
return;
17+
result.push(chars)
18+
return
1519
}
1620

1721
if(openParentheses<=n){
18-
solve(chars+"(",openParentheses+1,closedParentheses);
22+
solve(chars+'(',openParentheses+1,closedParentheses)
1923
}
2024

2125
if(closedParentheses<openParentheses){
22-
solve(chars+")",openParentheses,closedParentheses+1);
26+
solve(chars+')',openParentheses,closedParentheses+1)
2327
}
24-
};
28+
}
2529

26-
solve("",0,0);
30+
solve('',0,0)
2731

28-
returnresult;
29-
};
32+
returnresult
33+
}
3034

31-
export{generateParentheses};
35+
export{generateParentheses}
Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{generateCombinations}from"../all_combinations_of_size_k";
1+
import{generateCombinations}from'../all_combinations_of_size_k'
22

33
constcases=[
44
[
@@ -7,20 +7,31 @@ const cases = [
77
[
88
[1,2],
99
[1,3],
10+
[2,3]
11+
]
12+
],
13+
[
14+
4,
15+
2,
16+
[
17+
[1,2],
18+
[1,3],
19+
[1,4],
1020
[2,3],
11-
],
21+
[2,4],
22+
[3,4]
23+
]
1224
],
13-
[4,2,[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]],
1425
[0,0,[]],
15-
[2,3,[]],
16-
]asconst;
26+
[2,3,[]]
27+
]asconst
1728

18-
describe("AllCombinationsOfSizeK",()=>{
29+
describe('AllCombinationsOfSizeK',()=>{
1930
it.each(cases)(
20-
"create all combinations given n=%p and k=%p",
31+
'create all combinations given n=%p and k=%p',
2132
(n,k,expectedCombos)=>{
22-
constcombinations=generateCombinations(n,k);
23-
expect(combinations).toEqual(expectedCombos);
33+
constcombinations=generateCombinations(n,k)
34+
expect(combinations).toEqual(expectedCombos)
2435
}
25-
);
26-
});
36+
)
37+
})
Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
1-
import{generateParentheses}from"../generateparentheses";
1+
import{generateParentheses}from'../generateparentheses'
22

33
constcases:[number,string[]][]=[
4-
[0,[""]],
5-
[1,["()"]],
6-
[2,["(())","()()"]],
7-
[3,["((()))","(()())","(())()","()(())","()()()"]],
4+
[0,['']],
5+
[1,['()']],
6+
[2,['(())','()()']],
7+
[3,['((()))','(()())','(())()','()(())','()()()']],
88
[
99
4,
1010
[
11-
"(((())))",
12-
"((()()))",
13-
"((())())",
14-
"((()))()",
15-
"(()(()))",
16-
"(()()())",
17-
"(()())()",
18-
"(())(())",
19-
"(())()()",
20-
"()((()))",
21-
"()(()())",
22-
"()(())()",
23-
"()()(())",
24-
"()()()()",
25-
],
11+
'(((())))',
12+
'((()()))',
13+
'((())())',
14+
'((()))()',
15+
'(()(()))',
16+
'(()()())',
17+
'(()())()',
18+
'(())(())',
19+
'(())()()',
20+
'()((()))',
21+
'()(()())',
22+
'()(())()',
23+
'()()(())',
24+
'()()()()'
25+
]
2626
],
2727
[
2828
5,
2929
[
30-
"((((()))))",
31-
"(((()())))",
32-
"(((())()))",
33-
"(((()))())",
34-
"(((())))()",
35-
"((()(())))",
36-
"((()()()))",
37-
"((()())())",
38-
"((()()))()",
39-
"((())(()))",
40-
"((())()())",
41-
"((())())()",
42-
"((()))(())",
43-
"((()))()()",
44-
"(()((())))",
45-
"(()(()()))",
46-
"(()(())())",
47-
"(()(()))()",
48-
"(()()(()))",
49-
"(()()()())",
50-
"(()()())()",
51-
"(()())(())",
52-
"(()())()()",
53-
"(())((()))",
54-
"(())(()())",
55-
"(())(())()",
56-
"(())()(())",
57-
"(())()()()",
58-
"()(((())))",
59-
"()((()()))",
60-
"()((())())",
61-
"()((()))()",
62-
"()(()(()))",
63-
"()(()()())",
64-
"()(()())()",
65-
"()(())(())",
66-
"()(())()()",
67-
"()()((()))",
68-
"()()(()())",
69-
"()()(())()",
70-
"()()()(())",
71-
"()()()()()",
72-
],
73-
],
74-
];
30+
'((((()))))',
31+
'(((()())))',
32+
'(((())()))',
33+
'(((()))())',
34+
'(((())))()',
35+
'((()(())))',
36+
'((()()()))',
37+
'((()())())',
38+
'((()()))()',
39+
'((())(()))',
40+
'((())()())',
41+
'((())())()',
42+
'((()))(())',
43+
'((()))()()',
44+
'(()((())))',
45+
'(()(()()))',
46+
'(()(())())',
47+
'(()(()))()',
48+
'(()()(()))',
49+
'(()()()())',
50+
'(()()())()',
51+
'(()())(())',
52+
'(()())()()',
53+
'(())((()))',
54+
'(())(()())',
55+
'(())(())()',
56+
'(())()(())',
57+
'(())()()()',
58+
'()(((())))',
59+
'()((()()))',
60+
'()((())())',
61+
'()((()))()',
62+
'()(()(()))',
63+
'()(()()())',
64+
'()(()())()',
65+
'()(())(())',
66+
'()(())()()',
67+
'()()((()))',
68+
'()()(()())',
69+
'()()(())()',
70+
'()()()(())',
71+
'()()()()()'
72+
]
73+
]
74+
]
7575

76-
describe("Generate Parentheses",()=>{
76+
describe('Generate Parentheses',()=>{
7777
test.each(cases)(
78-
"generate all valid parentheses of input %n",
78+
'generate all valid parentheses of input %n',
7979
(n:number,expected:string[])=>{
80-
expect(generateParentheses(n)).toStrictEqual(expected);
80+
expect(generateParentheses(n)).toStrictEqual(expected)
8181
}
82-
);
83-
});
82+
)
83+
})

‎bit_manipulation/add_binary.ts‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
*@param secondBinaryNo - The second binary string.
66
*@returns The binary sum of the input strings.
77
*/
8-
exportfunctionaddBinary(firstBinaryNo:string,secondBinaryNo:string):string{
9-
letlengthOfFirstNumber:number=firstBinaryNo.length-1;
10-
letlengthOfSecondNumber:number=secondBinaryNo.length-1;
11-
constsolution:string[]=[];
12-
letcarry:number=0;
8+
exportfunctionaddBinary(
9+
firstBinaryNo:string,
10+
secondBinaryNo:string
11+
):string{
12+
letlengthOfFirstNumber:number=firstBinaryNo.length-1
13+
letlengthOfSecondNumber:number=secondBinaryNo.length-1
14+
constsolution:string[]=[]
15+
letcarry:number=0
1316

14-
while(lengthOfFirstNumber>=0||lengthOfSecondNumber>=0){
15-
letsum:number=carry;
16-
if(lengthOfFirstNumber>=0)sum+=parseInt(firstBinaryNo.charAt(lengthOfFirstNumber));
17-
if(lengthOfSecondNumber>=0)sum+=parseInt(secondBinaryNo.charAt(lengthOfSecondNumber));
18-
solution.push((sum%2).toString());
19-
carry=Math.floor(sum/2);
20-
lengthOfFirstNumber--;
21-
lengthOfSecondNumber--;
22-
}
17+
while(lengthOfFirstNumber>=0||lengthOfSecondNumber>=0){
18+
letsum:number=carry
19+
if(lengthOfFirstNumber>=0)
20+
sum+=parseInt(firstBinaryNo.charAt(lengthOfFirstNumber))
21+
if(lengthOfSecondNumber>=0)
22+
sum+=parseInt(secondBinaryNo.charAt(lengthOfSecondNumber))
23+
solution.push((sum%2).toString())
24+
carry=Math.floor(sum/2)
25+
lengthOfFirstNumber--
26+
lengthOfSecondNumber--
27+
}
2328

24-
if(carry!==0)solution.push(carry.toString());
29+
if(carry!==0)solution.push(carry.toString())
2530

26-
returnsolution.reverse().join('');
31+
returnsolution.reverse().join('')
2732
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp