Skip to content

Instantly share code, notes, and snippets.

@stknohg
Created April 4, 2017 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stknohg/6ca06fd836fad588ad1b8dff3cbf98cb to your computer and use it in GitHub Desktop.
Save stknohg/6ca06fd836fad588ad1b8dff3cbf98cb to your computer and use it in GitHub Desktop.
配列をn個ずつに分割する簡単なサンプル
# 配列をn個ずつに分割
$Array = 1..100
$n = 13
# 単純にスライスする
for ($i = 0; $i -lt $Array.Length; $i+=$n) {
Write-Host $Array[$i..($i+($n-1))]
}
# ForEach-Objectで頑張る
$Array | % {$b=@()}{$b+=$_;if($b.Length-ge$n){,$b;$b=@()}}{,$b} | % { Write-Host $_ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment