leetcode 30 days js challenge
Easy
Given an array arr
and a chunk size size
, return a chunked array. A chunked array contains the original elements in arr
, but consists of subarrays each of length size
. The length of the last subarray may be less than size
if arr.length
is not evenly divisible by size
.
You may assume the array is the output of JSON.parse
. In other words, it is valid JSON.
Please solve it without using lodash's _.chunk
function.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
arr is a valid JSON array
JSON.stringify(arr).length
<= 1051 <= size <= arr.length + 1
slice
解
SheepThur, May 25, 2023
reduce
解
SheepThur, May 25, 2023