File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 398
398
2665|[ Counter II] ( ./2665-counter-ii.js ) |Easy|
399
399
2666|[ Allow One Function Call] ( ./2666-allow-one-function-call.js ) |Easy|
400
400
2667|[ Create Hello World Function] ( ./2667-create-hello-world-function.js ) |Easy|
401
+ 2677|[ Chunk Array] ( ./2677-chunk-array.js ) |Easy|
401
402
2703|[ Return Length of Arguments Passed] ( ./2703-return-length-of-arguments-passed.js ) |Easy|
402
403
3110|[ Score of a String] ( ./3110-score-of-a-string.js ) |Easy|
403
404
3392|[ Count Subarrays of Length Three With a Condition] ( ./3392-count-subarrays-of-length-three-with-a-condition.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2677. Chunk Array
3
+ * https://leetcode.com/problems/chunk-array/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given an array arr and a chunk size size, return a chunked array.
7
+ *
8
+ * A chunked array contains the original elements in arr, but consists of subarrays each of
9
+ * length size. The length of the last subarray may be less than size if arr.length is not
10
+ * evenly divisible by size.
11
+ *
12
+ * You may assume the array is the output of JSON.parse. In other words, it is valid JSON.
13
+ *
14
+ * Please solve it without using lodash's _.chunk function.
15
+ */
16
+
17
+ /**
18
+ * @param {Array } arr
19
+ * @param {number } size
20
+ * @return {Array }
21
+ */
22
+ var chunk = function ( arr , size ) {
23
+ var result = [ ] ;
24
+
25
+ for ( let index = 0 ; index < arr . length ; ) {
26
+ result . push ( arr . slice ( index , index + size ) ) ;
27
+ index += size ;
28
+ }
29
+
30
+ return result ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments