File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed
solution/1500-1599/1562.Find Latest Group of Size M Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -289,6 +289,25 @@ func findLatestStep(arr []int, m int) int {
289
289
}
290
290
```
291
291
292
+ #### JavaScript
293
+
294
+ ``` javascript
295
+ const findLatestStep = function (arr , m ) {
296
+ let result = - 1 ;
297
+ const len = arr .length ;
298
+ const reOnes = new RegExp (` \\ b1{${ m} }\\ b` );
299
+ arr .reduce ( (accum , item , iIndex ) => {
300
+ accum[item- 1 ] = ' 1' ;
301
+ iIndex++ ;
302
+ if (iIndex >= m && reOnes .test (accum .join (' ' ))) {
303
+ result = iIndex;
304
+ }
305
+ return accum
306
+ }, [... (" " .repeat (len))] );
307
+ return result
308
+ }
309
+ ```
310
+
292
311
<!-- tabs:end -->
293
312
294
313
<!-- solution:end -->
Original file line number Diff line number Diff line change @@ -269,6 +269,25 @@ func findLatestStep(arr []int, m int) int {
269
269
}
270
270
```
271
271
272
+ #### JavaScript
273
+
274
+ ``` javascript
275
+ const findLatestStep = function (arr , m ) {
276
+ let result = - 1 ;
277
+ const len = arr .length ;
278
+ const reOnes = new RegExp (` \\ b1{${ m} }\\ b` );
279
+ arr .reduce ( (accum , item , iIndex ) => {
280
+ accum[item- 1 ] = ' 1' ;
281
+ iIndex++ ;
282
+ if (iIndex >= m && reOnes .test (accum .join (' ' ))) {
283
+ result = iIndex;
284
+ }
285
+ return accum
286
+ }, [... (" " .repeat (len))] );
287
+ return result
288
+ }
289
+ ```
290
+
272
291
<!-- tabs:end -->
273
292
274
293
<!-- solution:end -->
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } arr
3
+ * @param {number } m
4
+ * @return {number }
5
+ */
6
+ const findLatestStep = function ( arr , m ) {
7
+ let result = - 1 ;
8
+ const len = arr . length ;
9
+ const reOnes = new RegExp ( `\\b1{${ m } }\\b` ) ;
10
+ arr . reduce ( ( accum , item , iIndex ) => {
11
+ accum [ item - 1 ] = '1' ;
12
+ iIndex ++ ;
13
+ if ( iIndex >= m && reOnes . test ( accum . join ( '' ) ) ) {
14
+ result = iIndex ;
15
+ }
16
+ return accum
17
+ } , [ ...( " " . repeat ( len ) ) ] ) ;
18
+ return result
19
+ }
You can’t perform that action at this time.
0 commit comments