Skip to content

Commit d4d182b

Browse files
authored
Improved typescript tasks
1 parent eb660a9 commit d4d182b

File tree

28 files changed

+92
-85
lines changed

28 files changed

+92
-85
lines changed

src/main/kotlin/g2601_2700/s2618_check_if_object_instance_of_class/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function checkIfInstanceOf(obj: any, classFunction: any): boolean {
1111
return false
1212
}
1313

14-
/**
14+
/*
1515
* checkIfInstanceOf(new Date(), Date); // true
1616
*/
1717

src/main/kotlin/g2601_2700/s2619_array_prototype_last/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Array.prototype.last = function <T>(): T | -1 { //NOSONAR
1010
return this.length ? this.at(-1) : -1
1111
}
1212

13-
/**
13+
/*
1414
* const arr = [1, 2, 3];
1515
* arr.last(); // 3
1616
*/

src/main/kotlin/g2601_2700/s2620_counter/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function createCounter(n: number): () => number {
88
return fun
99
}
1010

11-
/**
11+
/*
1212
* const counter = createCounter(10)
1313
* counter() // 10
1414
* counter() // 11

src/main/kotlin/g2601_2700/s2621_sleep/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async function sleep(millis: number): Promise<void> {
66
})
77
}
88

9-
/**
9+
/*
1010
* let t = Date.now()
1111
* sleep(100).then(() => console.log(Date.now() - t)) // 100
1212
*/

src/main/kotlin/g2601_2700/s2622_cache_with_time_limit/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TimeLimitedCache {
2828
}
2929
}
3030

31-
/**
31+
/*
3232
* Your TimeLimitedCache object will be instantiated and called as such:
3333
* var obj = new TimeLimitedCache()
3434
* obj.set(1, 42, 1000); // false

src/main/kotlin/g2601_2700/s2623_memoize/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function memoize(fn: Fn): Fn {
1616
}
1717
}
1818

19-
/**
19+
/*
2020
* let callCount = 0;
2121
* const memoizedFn = memoize(function (a, b) {
2222
* callCount += 1;

src/main/kotlin/g2601_2700/s2624_snail_traversal/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Array.prototype.snail = function (rowsCount: number, colsCount: number): number[
1919
return res
2020
}
2121

22-
/**
22+
/*
2323
* const arr = [1,2,3,4];
2424
* arr.snail(1,4); // [[1,2,3,4]]
2525
*/

src/main/kotlin/g2601_2700/s2627_debounce/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function debounce(fn: F, t: number): F {
1212
}
1313
}
1414

15-
/**
15+
/*
1616
* const log = debounce(console.log, 100);
1717
* log('Hello'); // cancelled
1818
* log('Hello'); // cancelled

src/main/kotlin/g2601_2700/s2629_function_composition/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function compose(functions: F[]): F {
1515
}
1616
}
1717

18-
/**
18+
/*
1919
* const fn = compose([x => x + 1, x => 2 * x])
2020
* fn(4) // 9
2121
*/

src/main/kotlin/g2601_2700/s2630_memoize_ii/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function memoize(fn: Fn): Fn {
4343
}
4444
}
4545

46-
/**
46+
/*
4747
* let callCount = 0;
4848
* const memoizedFn = memoize(function (a, b) {
4949
* callCount += 1;

src/main/kotlin/g2601_2700/s2631_group_by/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Array.prototype.groupBy = function <T>(fn: (item: T) => string) { //NOSONAR
1919
return returnObject
2020
}
2121

22-
/**
22+
/*
2323
* [1,2,3].groupBy(String) // {"1":[1],"2":[2],"3":[3]}
2424
*/
2525

src/main/kotlin/g2601_2700/s2637_promise_time_limit/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function timeLimit(fn: Fn, t: number): Fn {
1515
}
1616
}
1717

18-
/**
18+
/*
1919
* const limited = timeLimit((t) => new Promise(res => setTimeout(res, t)), 100);
2020
* limited(150).catch(console.log) // "Time Limit Exceeded" at t=100ms
2121
*/

src/main/kotlin/g2601_2700/s2665_counter_ii/solution.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// #Easy #2023_07_25_Time_65_ms_(86.59%)_Space_44.8_MB_(93.23%)
22

33
type ReturnObj = {
4-
increment: () => number,
5-
decrement: () => number,
6-
reset: () => number,
4+
increment: () => number
5+
decrement: () => number
6+
reset: () => number
77
}
88

99
function createCounter(init: number): ReturnObj {
@@ -20,7 +20,7 @@ function createCounter(init: number): ReturnObj {
2020
reset: () => {
2121
n = init
2222
return n
23-
}
23+
},
2424
}
2525
}
2626

src/main/kotlin/g2601_2700/s2666_allow_one_function_call/solution.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// #Easy #2023_07_25_Time_53_ms_(93.29%)_Space_42.1_MB_(98.84%)
22

3-
function once<T extends (...args: T[]) => any>(fn: T):
4-
((...args: Parameters<T>) => ReturnType<T> | undefined) {
3+
function once<T extends (...args: T[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T> | undefined {
54
let hasRun: boolean
6-
return function (...args: T[]): ReturnType<T> | undefined {
7-
if (!hasRun) {
8-
hasRun = true
9-
return fn(...args)
10-
} else {
11-
return undefined
12-
}
13-
}
5+
return function (...args: T[]): ReturnType<T> | undefined {
6+
if (!hasRun) {
7+
hasRun = true
8+
return fn(...args)
9+
} else {
10+
return undefined
11+
}
12+
}
1413
}
1514

1615
/*

src/main/kotlin/g2601_2700/s2667_create_hello_world_function/solution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ function createHelloWorld() {
1111
* f(); // "Hello World"
1212
*/
1313

14-
export { createHelloWorld }
14+
export { createHelloWorld }

src/main/kotlin/g2601_2700/s2677_chunk_array/solution.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
function chunk(arr: any[], size: number): any[][] {
44
if (arr.length === 0) return []
55
if (size >= arr.length) return [arr]
6-
let i:number = 0
6+
let i: number = 0
77
let res: Array<Array<number>> = []
88
while (i < arr.length) {
9-
res.push(arr.slice(i, i+size))
9+
res.push(arr.slice(i, i + size))
1010
i += size
1111
}
1212
return res
1313
}
1414

15-
export { chunk }
15+
export { chunk }

src/main/kotlin/g2601_2700/s2693_call_function_with_custom_context/solution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare global {
66
}
77
}
88

9-
Function.prototype.callPolyfill = function (context, ...args): any {
9+
Function.prototype.callPolyfill = function (context, ...args): any { //NOSONAR
1010
let fn = this.bind(context)
1111
return fn(...args)
1212
}
@@ -16,4 +16,4 @@ Function.prototype.callPolyfill = function (context, ...args): any {
1616
* increment.callPolyfill({count: 1}); // 2
1717
*/
1818

19-
export { Function.prototype.callPolyfill }
19+
export {}

src/main/kotlin/g2601_2700/s2694_event_emitter/solution.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #Medium #2023_07_29_Time_45_ms_(99.58%)_Space_44.6_MB_(72.08%)
22

3-
type Callback = (...args: any[]) => any;
3+
type Callback = (...args: any[]) => any
44
type Subscription = {
55
unsubscribe: () => void
66
}
@@ -9,16 +9,15 @@ class EventEmitter {
99
subs: Record<string, Callback[]> = {}
1010

1111
subscribe(eventName: string, callback: Callback): Subscription {
12-
if (!this.subs[eventName])
13-
this.subs[eventName] = []
12+
if (!this.subs[eventName]) this.subs[eventName] = []
1413
const idx = this.subs[eventName].push(callback) - 1
1514
return {
16-
unsubscribe: () => this.subs[eventName].splice(idx, 1)
15+
unsubscribe: () => this.subs[eventName].splice(idx, 1),
1716
}
1817
}
1918

2019
emit(eventName: string, args: any[] = []): any[] {
21-
return this.subs[eventName]?.map(callback => callback(...args)) || []
20+
return this.subs[eventName]?.map((callback) => callback(...args)) || []
2221
}
2322
}
2423

@@ -34,4 +33,4 @@ class EventEmitter {
3433
* emitter.emit('onClick'); // []
3534
*/
3635

37-
export { EventEmitter }
36+
export { EventEmitter }
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// #Easy #2023_07_29_Time_40_ms_(100.00%)_Space_45_MB_(48.83%)
22

33
class ArrayWrapper {
4-
nums: number[];
4+
nums: number[]
55
constructor(nums: number[]) {
6-
this.nums = nums;
6+
this.nums = nums
77
}
88

99
valueOf() {
10-
return this.nums.reduce((n, a) => n + a, 0);
10+
return this.nums.reduce((n, a) => n + a, 0)
1111
}
1212

1313
toString() {
1414
return '[' + this.nums.join(',') + ']'
1515
}
16-
};
16+
}
1717

1818
/*
1919
* const obj1 = new ArrayWrapper([1,2]);
@@ -23,4 +23,4 @@ class ArrayWrapper {
2323
* String(obj2); // "[3,4]"
2424
*/
2525

26-
export { ArrayWrapper }
26+
export { ArrayWrapper }
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// #Easy #2023_07_29_Time_47_ms_(98.59%)_Space_41.5_MB_(100.00%)
22

33
function argumentsLength(...args: any[]): number {
4-
let result = 0
5-
for (let value of args) { // NOSONAR
6-
result += 1
7-
}
8-
return result
4+
let result = 0
5+
for (let value of args) { //NOSONAR
6+
result += 1
7+
}
8+
return result
99
}
1010

1111
/*
1212
* argumentsLength(1, 2, 3); // 3
1313
*/
1414

15-
export { argumentsLength }
15+
export { argumentsLength }

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
type ToBeOrNotToBe = {
44
toBe: (val: any) => boolean
55
notToBe: (val: any) => boolean
6-
};
6+
}
77

88
const expect = (val: any): ToBeOrNotToBe => ({
99
toBe: (equality: any) => {
1010
if (val !== equality) {
11-
throw new Error("Not Equal")
11+
throw new Error('Not Equal')
1212
}
1313
return true
1414
},
1515
notToBe: (equality: any) => {
1616
if (val === equality) {
17-
throw new Error("Equal")
17+
throw new Error('Equal')
1818
}
1919
return true
2020
},
@@ -25,4 +25,4 @@ const expect = (val: any): ToBeOrNotToBe => ({
2525
* expect(5).notToBe(5); // throws "Equal"
2626
*/
2727

28-
export { expect }
28+
export { expect }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ function compactObject(obj: Obj): Obj {
1313
return retArr
1414
} else if (obj !== null && typeof obj === 'object') {
1515
let retObj = {}
16-
for(const key of Object.keys(obj)) {
17-
if(obj[key]) {
16+
for (const key of Object.keys(obj)) {
17+
if (obj[key]) {
1818
retObj[key] = compactObject(obj[key])
1919
}
2020
}
2121
return retObj
22-
}
22+
}
2323
return obj
2424
}
2525

src/test/kotlin/g2601_2700/s2667_create_hello_world_function/solution.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test('createHelloWorld', () => {
77
expect(counter()).toEqual('Hello World')
88
})
99

10-
test('createHelloWorld', () => {
10+
test('createHelloWorld2', () => {
1111
const counter = createHelloWorld()
1212
expect(counter({}, null, 42)).toEqual('Hello World')
1313
})

src/test/kotlin/g2601_2700/s2677_chunk_array/solution.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import { chunk } from 'src/main/kotlin/g2601_2700/s2677_chunk_array/solution'
33
import { expect, test } from 'vitest'
44

55
test('chunk', () => {
6-
expect(chunk([1,2,3,4,5], 1)).toEqual([[1],[2],[3],[4],[5]])
6+
expect(chunk([1, 2, 3, 4, 5], 1)).toEqual([[1], [2], [3], [4], [5]])
77
})
88

99
test('chunk2', () => {
10-
expect(chunk([1,9,6,3,2], 3)).toEqual([[1,9,6],[3,2]])
10+
expect(chunk([1, 9, 6, 3, 2], 3)).toEqual([
11+
[1, 9, 6],
12+
[3, 2],
13+
])
1114
})
1215

1316
test('chunk3', () => {
14-
expect(chunk([8,5,3,2,6], 6)).toEqual([[8,5,3,2,6]])
17+
expect(chunk([8, 5, 3, 2, 6], 6)).toEqual([[8, 5, 3, 2, 6]])
1518
})
1619

1720
test('chunk4', () => {

0 commit comments

Comments
 (0)