I am learning Dart. I have simple JS code that split array to number of parts like:
2: [1,2,4,6,8], [14,17,18,19]
3: [1,2,4], [6,8,14], [17,18,19]
4: [1,2], [4,6], [8,14], [17,18,19]
Could anybody help me with converting follow code to Dart?
function split(arr, numParts) {
const partSize = arr.length / numParts | 0;
return Array
.from({ length: numParts }, (n, i) => i * partSize)
.map((n, i, a) => arr.slice(n, a[i + 1]));
}
console.log(split([1,2,4,6,8,14,17,18,19,20], 3)); // [1,2,4] [6,8,14] [17,18,19,20]
I was able to convert only few first lines:
split(List<int> arr, int numParts) {
var partSize = arr.length / numParts;
}
But need help with rest part.