Skip to content

Commit cee93c8

Browse files
committed
chore: convert js to ts
1 parent cb71967 commit cee93c8

File tree

16 files changed

+152
-113
lines changed

16 files changed

+152
-113
lines changed

packages/example/src/1week/01.js

-7
This file was deleted.

packages/example/src/1week/01.test.js

-7
This file was deleted.

packages/example/src/1week/01.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { lineFunction } from "./01";
2+
3+
describe("lineFunction", () => {
4+
it("case: 1", () => {
5+
expect(lineFunction()).toBe(7);
6+
});
7+
});

packages/example/src/1week/01.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var x = 2;
2+
3+
export function lineFunction() {
4+
return 2 * x + 3;
5+
}

packages/example/src/1week/02.test.js

-7
This file was deleted.

packages/example/src/1week/02.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { accumulate } from "./02";
2+
3+
describe("accumulate", () => {
4+
it("case: 1", () => {
5+
expect(accumulate([1, 2, 3, 4, 5])).toBe(15);
6+
});
7+
});
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function accumulate(arr) {
1+
export function accumulate(arr: number[]): number {
22
let accumulator = 0;
33

44
for (let i = 0; i < arr.length; i++) {
@@ -7,5 +7,3 @@ function accumulate(arr) {
77

88
return accumulator;
99
}
10-
11-
exports.accumulate = accumulate;

packages/example/src/1week/03.test.js renamed to packages/example/src/1week/03.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { multiDimensionalAccumulate } = require('./03.js');
1+
import { multiDimensionalAccumulate } from "./03";
22

3-
describe('multiDimensionalAccumulate', () => {
4-
it('case: 1', () => {
3+
describe("multiDimensionalAccumulate", () => {
4+
it("case: 1", () => {
55
const multiDimensionalArr = [
66
[1, 2, 3, 4, 5, 6, 7, 8, 9],
77
[9, 8, 7, 6, 5, 4, 3, 2, 1],

packages/example/src/1week/03.js renamed to packages/example/src/1week/03.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
function multiDimensionalAccumulate(multiDimensionalArr) {
1+
export function multiDimensionalAccumulate(
2+
multiDimensionalArr: number[][],
3+
): number {
24
let accumulator = 0;
35

46
for (let i = 0; i < multiDimensionalArr.length; i++) {
@@ -11,5 +13,3 @@ function multiDimensionalAccumulate(multiDimensionalArr) {
1113

1214
return accumulator;
1315
}
14-
15-
exports.multiDimensionalAccumulate = multiDimensionalAccumulate;

packages/example/src/1week/04.test.js

-27
This file was deleted.

packages/example/src/1week/04.test.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { convertToConditionalUpperCase } from "./04";
2+
3+
describe("convertToConditionalUpperCase", () => {
4+
it("case: 1", () => {
5+
const words = [
6+
"piece",
7+
"functional",
8+
"of",
9+
"sentence",
10+
"cake",
11+
"perspective",
12+
];
13+
expect(convertToConditionalUpperCase(words)).toEqual([
14+
"piece",
15+
"FUNCTIONAL",
16+
"of",
17+
"SENTENCE",
18+
"cake",
19+
"PERSPECTIVE",
20+
]);
21+
});
22+
23+
it("case: 2", () => {
24+
const words = [
25+
"PIECE",
26+
"FUNCTIONAL",
27+
"OF",
28+
"SENTENCE",
29+
"CAKE",
30+
"PERSPECTIVE",
31+
];
32+
expect(convertToConditionalUpperCase(words)).toEqual([
33+
"piece",
34+
"FUNCTIONAL",
35+
"of",
36+
"SENTENCE",
37+
"cake",
38+
"PERSPECTIVE",
39+
]);
40+
});
41+
});

packages/example/src/1week/04.js renamed to packages/example/src/1week/04.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function convertToConditionalUpperCase(words) {
1+
export function convertToConditionalUpperCase(words: string[]): string[] {
22
let capitalized = [];
33

44
for (let i = 0; i < words.length; i++) {
@@ -11,5 +11,3 @@ function convertToConditionalUpperCase(words) {
1111

1212
return capitalized;
1313
}
14-
15-
exports.convertToConditionalUpperCase = convertToConditionalUpperCase;

packages/example/src/1week/05.js

-5
This file was deleted.

packages/example/src/1week/05.test.js

-48
This file was deleted.

packages/example/src/1week/05.test.ts

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { deepCopy } from "./05";
2+
3+
describe("deepCopy", () => {
4+
it("case: 1", () => {
5+
const obj = {};
6+
const obj2 = {
7+
1: undefined,
8+
a: [],
9+
undefined: {
10+
arrayObj: [1, 2, 3, 4, 5],
11+
mapObj: new Map(),
12+
setObj: new Set(),
13+
aaa: {
14+
bbb: {
15+
ccc: {
16+
ddd: {
17+
fp: "very wonderful!",
18+
},
19+
},
20+
},
21+
},
22+
},
23+
children: {
24+
first: 0,
25+
second: "함수형 프로그래밍",
26+
forth: [
27+
{
28+
string: "string",
29+
number: 123,
30+
bool: false,
31+
nul: null,
32+
},
33+
{
34+
undef: undefined,
35+
inf: Infinity,
36+
re: /.*/,
37+
},
38+
],
39+
},
40+
2: null,
41+
};
42+
43+
expect(deepCopy(obj)).toEqual({});
44+
expect(deepCopy(obj2)).toEqual({
45+
1: undefined,
46+
a: [],
47+
undefined: {
48+
arrayObj: [1, 2, 3, 4, 5],
49+
mapObj: new Map(),
50+
setObj: new Set(),
51+
aaa: {
52+
bbb: {
53+
ccc: {
54+
ddd: {
55+
fp: "very wonderful!",
56+
},
57+
},
58+
},
59+
},
60+
},
61+
children: {
62+
first: 0,
63+
second: "함수형 프로그래밍",
64+
forth: [
65+
{
66+
string: "string",
67+
number: 123,
68+
bool: false,
69+
nul: null,
70+
},
71+
{
72+
undef: undefined,
73+
inf: Infinity,
74+
re: /.*/,
75+
},
76+
],
77+
},
78+
2: null,
79+
});
80+
});
81+
});

packages/example/src/1week/05.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function deepCopy(obj: Record<string, any>): Record<string, any> {
2+
return obj;
3+
}

0 commit comments

Comments
 (0)