Created
April 4, 2017 03:49
-
-
Save stknohg/6ca06fd836fad588ad1b8dff3cbf98cb to your computer and use it in GitHub Desktop.
配列をn個ずつに分割する簡単なサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 配列を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