Skip to content

Commit d91c080

Browse files
committed
Fix splitting list smaller than specified count
1 parent c9aae72 commit d91c080

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Private/Split-Every.ps1

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ Function Split-Every($list, $count=4) {
33

44
$blocks = [Math]::Floor($list.Count / $count)
55
$leftOver = $list.Count % $count
6+
$start=0
67
for($i=0; $i -lt $blocks; $i++) {
78
$end = $count * ($i + 1) - 1
89

910
$aggregateList += @(,$list[$start..$end])
1011
$start = $end + 1
1112
}
1213
if($leftOver -gt 0) {
13-
$aggregateList += @(,$list[$start..($end+$leftOver)])
14+
$aggregateList += @(,$list[$start..($start+$leftOver-1)])
1415
}
15-
16-
$aggregateList
16+
If ($list.Count -le $count) {$aggregateList=@(,$aggregateList)}
17+
$aggregateList
1718
}

0 commit comments

Comments
 (0)