Skip to content

Commit c8608d2

Browse files
authored
Updated tasks
1 parent 868d43c commit c8608d2

File tree

12 files changed

+507
-525
lines changed

12 files changed

+507
-525
lines changed

README.md

Lines changed: 458 additions & 458 deletions
Large diffs are not rendered by default.

src/main/kotlin/g2601_2700/s2618_check_if_object_instance_of_class/readme.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,5 @@ function checkIfInstanceOf(obj: any, classFunction: any): boolean {
6363
return false
6464
}
6565

66-
/*
67-
* checkIfInstanceOf(new Date(), Date); // true
68-
*/
69-
7066
export { checkIfInstanceOf }
7167
```

src/main/kotlin/g2601_2700/s2619_array_prototype_last/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ declare global {
3838
}
3939
}
4040

41-
Array.prototype.last = function <T>(): T | -1 { //NOSONAR
42-
return this.length ? this.at(-1) : -1
41+
Array.prototype.last = function () { //NOSONAR
42+
return this.length !== 0 ? this[this.length - 1] : -1
4343
}
4444

4545
/*

src/main/kotlin/g2601_2700/s2621_sleep/readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ Given a positive integer `millis`, write an asynchronous function that sleeps fo
3131

3232
```typescript
3333
async function sleep(millis: number): Promise<void> {
34-
return new Promise<void>((resolve, reject) => {
35-
setTimeout(resolve, millis)
36-
})
34+
await new Promise((resolve) => setTimeout(resolve, millis))
3735
}
3836

3937
/*

src/main/kotlin/g2601_2700/s2626_array_reduce_transformation/readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ function reduce(nums: number[], fn: Fn, init: number): number {
7373
nums.forEach((num) => {
7474
accumulator = fn(accumulator, num)
7575
})
76-
7776
return accumulator
7877
}
7978

src/main/kotlin/g2601_2700/s2629_function_composition/readme.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,11 @@ Evaluating from right to left ...
6767
type F = (x: number) => number
6868

6969
function compose(functions: F[]): F {
70-
const n = functions.length
71-
7270
return function (x) {
73-
for (let i = n - 1; i >= 0; i--) {
74-
const fn = functions[i]
75-
x = fn(x)
71+
if (functions.length == 0) return x
72+
for (let ind = functions.length - 1; ind >= 0; ind--) {
73+
x = functions[ind](x)
7674
}
77-
7875
return x
7976
}
8077
}

src/main/kotlin/g2601_2700/s2637_promise_time_limit/readme.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,13 @@ t = 1000
104104
type Fn = (...params: any[]) => Promise<any>
105105

106106
function timeLimit(fn: Fn, t: number): Fn {
107-
return async function (...args: any[]): Promise<any> {
108-
const fns = fn(...args)
109-
const timeLimitPromise = new Promise((_, reject) => {
107+
return async function (...args) {
108+
const timeout = new Promise<any>((_, reject) => {
110109
setTimeout(() => {
111-
reject(new Error('Time Limit Exceeded'))
110+
reject('Time Limit Exceeded') //NOSONAR
112111
}, t)
113112
})
114-
115-
return Promise.race([fns, timeLimitPromise])
113+
return Promise.race([fn(...args), timeout])
116114
}
117115
}
118116

src/main/kotlin/g2601_2700/s2649_nested_array_generator/readme.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,9 @@ A **multi-dimensional array** is a recursive data structure that contains both i
4747
type MultidimensionalArray = (MultidimensionalArray | number)[]
4848

4949
function* inorderTraversal(arr: MultidimensionalArray): Generator<number, void, unknown> {
50-
if (!Array.isArray(arr)) {
51-
yield arr
52-
return
53-
}
54-
55-
for (let value of arr) {
56-
yield* inorderTraversal(value as MultidimensionalArray)
57-
}
50+
for (const item of arr)
51+
if (Array.isArray(item)) yield* inorderTraversal(item)
52+
else yield item
5853
}
5954

6055
/*

src/main/kotlin/g2601_2700/s2661_first_completely_painted_row_or_column/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Return _the smallest index_ `i` _at which either a row or a column will be compl
1313

1414
**Example 1:**
1515

16-
![](image explanation for example 1)![image explanation for example 1](https://assets.leetcode.com/uploads/2023/01/18/grid1.jpg)
16+
![image explanation for example 1](https://assets.leetcode.com/uploads/2023/01/18/grid1.jpg)
1717

1818
**Input:** arr = [1,3,4,2], mat = \[\[1,4],[2,3]]
1919

src/main/kotlin/g2601_2700/s2666_allow_one_function_call/readme.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,17 @@ Given a function `fn`, return a new function that is identical to the original f
4444
## Solution
4545

4646
```typescript
47-
function once<T extends (...args: T[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T> | undefined {
48-
let hasRun: boolean
49-
return function (...args: T[]): ReturnType<T> | undefined {
50-
if (!hasRun) {
51-
hasRun = true
47+
type Fn = (...args: any[]) => any
48+
49+
function once(fn: Fn): Fn {
50+
let wasCalled = false
51+
return function (...args) {
52+
if (!wasCalled) {
53+
wasCalled = true
5254
return fn(...args)
53-
} else {
54-
return undefined
5555
}
5656
}
5757
}
5858

59-
/*
60-
* let fn = (a,b,c) => (a + b + c)
61-
* let onceFn = once(fn)
62-
*
63-
* onceFn(1,2,3); // 6
64-
* onceFn(2,3,6); // returns undefined without calling fn
65-
*/
66-
6759
export { once }
6860
```

0 commit comments

Comments
 (0)