Skip to content

Commit 2371e5f

Browse files
authored
Improved TypeScript tasks
1 parent 4b8f903 commit 2371e5f

File tree

25 files changed

+109
-72
lines changed

25 files changed

+109
-72
lines changed
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #Medium #2023_07_16_Time_100_ms_(91.86%)_Space_52.3_MB_(63.91%)
1+
// #Medium #2023_08_30_Time_82_ms_(99.55%)_Space_52.1_MB_(79.46%)
22

33
function checkIfInstanceOf(obj: any, classFunction: any): boolean {
44
if (obj === null || obj === undefined || typeof classFunction !== 'function') return false
@@ -11,8 +11,4 @@ function checkIfInstanceOf(obj: any, classFunction: any): boolean {
1111
return false
1212
}
1313

14-
/*
15-
* checkIfInstanceOf(new Date(), Date); // true
16-
*/
17-
1814
export { checkIfInstanceOf }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// #Easy #2023_07_16_Time_51_ms_(94.69%)_Space_43.2_MB_(27.55%)
1+
// #Easy #2023_08_31_Time_41_ms_(98.99%)_Space_42_MB_(96.92%)
22

33
declare global {
44
interface Array<T> {
55
last(): T | -1
66
}
77
}
88

9-
Array.prototype.last = function <T>(): T | -1 { //NOSONAR
10-
return this.length ? this.at(-1) : -1
9+
Array.prototype.last = function () { //NOSONAR
10+
return this.length !== 0 ? this[this.length - 1] : -1
1111
}
1212

1313
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #Easy #2023_07_16_Time_53_ms_(91.77%)_Space_43.1_MB_(46.69%)
1+
// #Easy #2023_08_31_Time_43_ms_(98.60%)_Space_42.2_MB_(91.27%)
22

33
function createCounter(n: number): () => number {
44
const fun = function () {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// #Easy #2023_07_16_Time_49_ms_(97.92%)_Space_42.1_MB_(96.08%)
1+
// #Easy #2023_08_31_Time_40_ms_(99.59%)_Space_42.3_MB_(77.98%)
22

33
async function sleep(millis: number): Promise<void> {
4-
return new Promise<void>((resolve, reject) => {
5-
setTimeout(resolve, millis)
6-
})
4+
await new Promise((resolve) => setTimeout(resolve, millis))
75
}
86

97
/*

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
@@ -1,4 +1,4 @@
1-
// #Medium #2023_07_16_Time_59_ms_(86.77%)_Space_42.4_MB_(94.28%)
1+
// #Medium #2023_08_31_Time_51_ms_(94.82%)_Space_42.2_MB_(94.26%)
22

33
class TimeLimitedCache {
44
private keyMap: Map<number, any>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #Medium #2023_07_16_Time_326_ms_(92.92%)_Space_108.8_MB_(38.51%)
1+
// #Medium #2023_08_31_Time_264_ms_(97.20%)_Space_109.2_MB_(32.97%)
22

33
type Fn = (...params: any) => any
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #Medium #2023_07_16_Time_215_ms_(83.48%)_Space_64.2_MB_(46.15%)
1+
// #Medium #2023_08_31_Time_175_ms_(92.96%)_Space_64.2_MB_(32.75%)
22

33
declare global {
44
interface Array<T> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #Medium #2023_07_16_Time_107_ms_(88.76%)_Space_62.5_MB_(88.18%)
1+
// #Medium #2023_08_31_Time_84_ms_(98.71%)_Space_61.8_MB_(94.52%)
22

33
type MultiDimensionalArray = (number | MultiDimensionalArray)[]
44

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #Easy #2023_07_17_Time_54_ms_(95.99%)_Space_44.8_MB_(40.89%)
1+
// #Easy #2023_08_31_Time_52_ms_(91.40%)_Space_44.2_MB_(82.03%)
22

33
type Fn = (accum: number, curr: number) => number
44

@@ -7,7 +7,6 @@ function reduce(nums: number[], fn: Fn, init: number): number {
77
nums.forEach((num) => {
88
accumulator = fn(accumulator, num)
99
})
10-
1110
return accumulator
1211
}
1312

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #Medium #2023_07_17_Time_64_ms_(73.92%)_Space_43.1_MB_(35.10%)
1+
// #Medium #2023_08_31_Time_50_ms_(98.23%)_Space_42.5_MB_(83.54%)
22

33
type F = (...p: any[]) => any
44

0 commit comments

Comments
 (0)