Skip to content

Commit e4e8bd2

Browse files
committed
https://leetcode.cn/problems/group-by
1 parent de64b87 commit e4e8bd2

File tree

2 files changed

+117
-97
lines changed

2 files changed

+117
-97
lines changed

README.md

Lines changed: 99 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,103 @@ Step 2. Add the dependency
4343
</dependency>
4444
```
4545

46+
#### 安装教程
47+
48+
1.安装`deno`
49+
50+
<https://deno.land/#installation>
51+
52+
2.安装 `udd`
53+
54+
<https://deno.land/x/udd#installation>
55+
56+
#### 使用说明
57+
58+
1.测试
59+
60+
```bash
61+
deno task test
62+
```
63+
64+
2.升级依赖
65+
66+
```bash
67+
deno task udd
68+
```
69+
70+
3.格式化
71+
72+
```shell
73+
deno task fmt
74+
```
75+
76+
4.lint
77+
78+
```bash
79+
deno task lint
80+
```
81+
82+
5.type check
83+
84+
```bash
85+
deno task check
86+
```
87+
88+
### Deno
89+
90+
<https://deno.land/x/masx200_leetcode_test>
91+
92+
<https://denopkg.com/masx200/leetcode-test>
93+
94+
<https://cdn.jsdelivr.net/gh/masx200/leetcode-test/>
95+
96+
1.导入模块
97+
98+
指定版本号
99+
100+
```ts
101+
import {} from "https://deno.land/x/[email protected]/mod.ts";
102+
```
103+
104+
2.使用举例
105+
106+
```ts
107+
import { climbing_stairs_bigint } from "https://deno.land/x/[email protected]/mod.ts";
108+
```
109+
110+
```ts
111+
import climbing_stairs from "https://deno.land/x/[email protected]/climbing-stairs/index.ts";
112+
```
113+
114+
### Golang
115+
116+
```bash
117+
go get github.com/masx200/leetcode-test
118+
```
119+
120+
<https://pkg.go.dev/github.com/masx200/leetcode-test>
121+
122+
#### 参与贡献
123+
124+
1. Fork 本仓库
125+
2. 新建 Feat_xxx 分支
126+
3. 提交代码
127+
4. 新建 Pull Request
128+
129+
### Building a Monorepo in Golang
130+
131+
<https://earthly.dev/blog/golang-monorepo/>
132+
133+
.vscode/settings.json
134+
135+
```json
136+
{
137+
"gopls": {
138+
"experimentalWorkspaceModule": true
139+
}
140+
}
141+
```
142+
46143
##### 包含的内容如下
47144

48145
<details>
@@ -2445,101 +2542,6 @@ https://leetcode.cn/problems/promise-time-limit/
24452542

24462543
https://leetcode.cn/problems/design-cancellable-function/
24472544

2448-
</details>
2545+
https://leetcode.cn/problems/group-by
24492546

2450-
#### 安装教程
2451-
2452-
1.安装`deno`
2453-
2454-
<https://deno.land/#installation>
2455-
2456-
2.安装 `udd`
2457-
2458-
<https://deno.land/x/udd#installation>
2459-
2460-
#### 使用说明
2461-
2462-
1.测试
2463-
2464-
```bash
2465-
deno task test
2466-
```
2467-
2468-
2.升级依赖
2469-
2470-
```bash
2471-
deno task udd
2472-
```
2473-
2474-
3.格式化
2475-
2476-
```shell
2477-
deno task fmt
2478-
```
2479-
2480-
4.lint
2481-
2482-
```bash
2483-
deno task lint
2484-
```
2485-
2486-
5.type check
2487-
2488-
```bash
2489-
deno task check
2490-
```
2491-
2492-
### Deno
2493-
2494-
<https://deno.land/x/masx200_leetcode_test>
2495-
2496-
<https://denopkg.com/masx200/leetcode-test>
2497-
2498-
<https://cdn.jsdelivr.net/gh/masx200/leetcode-test/>
2499-
2500-
1.导入模块
2501-
2502-
指定版本号
2503-
2504-
```ts
2505-
import {} from "https://deno.land/x/[email protected]/mod.ts";
2506-
```
2507-
2508-
2.使用举例
2509-
2510-
```ts
2511-
import { climbing_stairs_bigint } from "https://deno.land/x/[email protected]/mod.ts";
2512-
```
2513-
2514-
```ts
2515-
import climbing_stairs from "https://deno.land/x/[email protected]/climbing-stairs/index.ts";
2516-
```
2517-
2518-
### Golang
2519-
2520-
```bash
2521-
go get github.com/masx200/leetcode-test
2522-
```
2523-
2524-
<https://pkg.go.dev/github.com/masx200/leetcode-test>
2525-
2526-
#### 参与贡献
2527-
2528-
1. Fork 本仓库
2529-
2. 新建 Feat_xxx 分支
2530-
3. 提交代码
2531-
4. 新建 Pull Request
2532-
2533-
### Building a Monorepo in Golang
2534-
2535-
<https://earthly.dev/blog/golang-monorepo/>
2536-
2537-
.vscode/settings.json
2538-
2539-
```json
2540-
{
2541-
"gopls": {
2542-
"experimentalWorkspaceModule": true
2543-
}
2544-
}
2545-
```
2547+
</details>

group-by/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
declare global {
2+
interface Array<T> {
3+
groupBy(fn: (item: T) => string): Record<string, T[]>;
4+
}
5+
}
6+
7+
Array.prototype.groupBy = function (fn) {
8+
const obj: Record<string, any[]> = {};
9+
10+
for (const v of this) {
11+
(obj[fn(v)] ??= []).push(v);
12+
}
13+
return obj;
14+
};
15+
16+
/**
17+
* [1,2,3].groupBy(String) // {"1":[1],"2":[2],"3":[3]}
18+
*/

0 commit comments

Comments
 (0)