Skip to content

Commit 40bd805

Browse files
authored
feat: add js solution to lc problem: No.1701 (doocs#3238)
1 parent b8cc919 commit 40bd805

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

solution/1700-1799/1701.Average Waiting Time/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ function averageWaitingTime(customers: number[][]): number {
161161
}
162162
```
163163

164+
#### JavaScript
165+
166+
```js
167+
function averageWaitingTime(customers) {
168+
let [tot, t] = [0, 0];
169+
for (const [a, b] of customers) {
170+
t = Math.max(t, a) + b;
171+
tot += t - a;
172+
}
173+
return tot / customers.length;
174+
}
175+
```
176+
164177
<!-- tabs:end -->
165178

166179
<!-- solution:end -->

solution/1700-1799/1701.Average Waiting Time/README_EN.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ function averageWaitingTime(customers: number[][]): number {
159159
}
160160
```
161161

162+
#### JavaScript
163+
164+
```js
165+
function averageWaitingTime(customers) {
166+
let [tot, t] = [0, 0];
167+
for (const [a, b] of customers) {
168+
t = Math.max(t, a) + b;
169+
tot += t - a;
170+
}
171+
return tot / customers.length;
172+
}
173+
```
174+
162175
<!-- tabs:end -->
163176

164177
<!-- solution:end -->
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function averageWaitingTime(customers) {
2+
let [tot, t] = [0, 0];
3+
for (const [a, b] of customers) {
4+
t = Math.max(t, a) + b;
5+
tot += t - a;
6+
}
7+
return tot / customers.length;
8+
}

0 commit comments

Comments
 (0)