Skip to content

Commit 9b5afae

Browse files
authored
Improved tasks
1 parent 094e8cc commit 9b5afae

File tree

6 files changed

+59
-44
lines changed

6 files changed

+59
-44
lines changed

src/main/kotlin/g2701_2800/s2724_sort_by/solution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// #Easy #2023_08_03_Time_132_ms_(96.70%)_Space_56.9_MB_(73.28%)
22

33
function sortBy(arr: any[], fn: Function): any[] {
4-
let swap: any = (a: any, b: any)=>{return (fn(a) < fn(b))?-1:1;};
4+
let swap: any = (a: any, b: any) => {
5+
return fn(a) < fn(b) ? -1 : 1
6+
}
57
return arr.sort(swap)
68
}
79

src/main/kotlin/g2701_2800/s2725_interval_cancellation/solution.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ function cancellable(fn: Function, args: any[], t: number): Function {
2121
* const diff = Math.floor(performance.now() - start)
2222
* result.push({"time": diff, "returned": fn(...argsArr)})
2323
* }
24-
*
24+
*
2525
* const cancel = cancellable(log, args, t);
2626
*
2727
* setTimeout(() => {
2828
* cancel()
2929
* }, cancelT)
30-
*
30+
*
3131
* setTimeout(() => {
3232
* console.log(result) // [
3333
* // {"time":0,"returned":8},
3434
* // {"time":20,"returned":8},
35-
* // {"time":40,"returned":8},
35+
* // {"time":40,"returned":8},
3636
* // {"time":60,"returned":8},
3737
* // {"time":80,"returned":8},
3838
* // {"time":100,"returned":8}
3939
* // ]
40-
* }, cancelT + t + 15)
40+
* }, cancelT + t + 15)
4141
*/
4242

4343
export { cancellable }
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
// #Easy #2023_08_03_Time_43_ms_(99.15%)_Space_43.4_MB_(9.15%)
22

33
class Calculator {
4-
init: number;
5-
6-
constructor(value : number) {
7-
this.init = value;
8-
}
9-
10-
add(value : number) : Calculator {//NOSONAR
11-
this.init += value;
12-
return this;
13-
}
14-
15-
subtract(value : number) : Calculator {//NOSONAR
16-
this.init -= value;
17-
return this;
18-
}
19-
20-
multiply(value : number) : Calculator {//NOSONAR
21-
this.init *= value;
22-
return this;
23-
}
24-
25-
divide(value : number) : Calculator {//NOSONAR
26-
if (value === 0) throw Error("Division by zero is not allowed");
27-
this.init /= value;
28-
return this;
29-
}
30-
31-
power(value : number) : Calculator {//NOSONAR
32-
this.init = this.init ** value;
33-
return this;
34-
}
35-
36-
getResult() : number {
37-
return this.init;
38-
}
4+
init: number
5+
6+
constructor(value: number) {
7+
this.init = value
8+
}
9+
10+
add(value: number): Calculator { //NOSONAR
11+
this.init += value
12+
return this
13+
}
14+
15+
subtract(value: number): Calculator { //NOSONAR
16+
this.init -= value
17+
return this
18+
}
19+
20+
multiply(value: number): Calculator { //NOSONAR
21+
this.init *= value
22+
return this
23+
}
24+
25+
divide(value: number): Calculator { //NOSONAR
26+
if (value === 0) throw Error('Division by zero is not allowed')
27+
this.init /= value
28+
return this
29+
}
30+
31+
power(value: number): Calculator { //NOSONAR
32+
this.init = this.init ** value
33+
return this
34+
}
35+
36+
getResult(): number {
37+
return this.init
38+
}
3939
}
4040

4141
export { Calculator }

src/main/kotlin/g2701_2800/s2727_is_object_empty/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
function isEmpty(obj: Record<string, any> | any[]): boolean {
44
return Object.keys(obj).length === 0
5-
};
5+
}
66

77
export { isEmpty }

src/test/kotlin/g2701_2800/s2724_sort_by/solution.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,22 @@ test('sortBy', () => {
77
})
88

99
test('sortBy2', () => {
10-
expect(sortBy([{"x": 1}, {"x": 0}, {"x": -1}], (d) => d.x)).toEqual([{"x": -1}, {"x": 0}, {"x": 1}])
10+
expect(sortBy([{ x: 1 }, { x: 0 }, { x: -1 }], (d) => d.x)).toEqual([{ x: -1 }, { x: 0 }, { x: 1 }])
1111
})
1212

1313
test('sortBy3', () => {
14-
expect(sortBy([[3, 4], [5, 2], [10, 1]], (x) => x[1])).toEqual([[10, 1], [5, 2], [3, 4]])
14+
expect(
15+
sortBy(
16+
[
17+
[3, 4],
18+
[5, 2],
19+
[10, 1],
20+
],
21+
(x) => x[1],
22+
),
23+
).toEqual([
24+
[10, 1],
25+
[5, 2],
26+
[3, 4],
27+
])
1528
})

src/test/kotlin/g2701_2800/s2727_is_object_empty/solution.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isEmpty } from 'src/main/kotlin/g2701_2800/s2727_is_object_empty/soluti
33
import { expect, test } from 'vitest'
44

55
test('isEmpty', () => {
6-
expect(isEmpty({"x": 5, "y": 42})).toEqual(false)
6+
expect(isEmpty({ x: 5, y: 42 })).toEqual(false)
77
})
88

99
test('isEmpty2', () => {

0 commit comments

Comments
 (0)