Skip to content

Instantly share code, notes, and snippets.

@45413
Last active November 8, 2017 01:02
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 45413/55762024dc139cbaca0ff6269e3c5a46 to your computer and use it in GitHub Desktop.
Save 45413/55762024dc139cbaca0ff6269e3c5a46 to your computer and use it in GitHub Desktop.
# Genereate Dummy array of numbers (does not matter that they are sequental)
$array = 1..20
# Get group size
$size = (($array.Count / 5 ))
# Create empty array to populate with multidemensional array
$rules = @()
# For 0 to count of array.
for ($currentIndex = 0; $currentIndex -lt $array.Count;) {
# set next counter by adding size to current
$nextIndex = $currentIndex + $size
# check if we are going past the end of the array
if ($nextIndex > $array.count) {
# set to end of the array
$nextIndex = $array.count
}
# append next array of values to rules
$rules += @($array[$currentIndex], $array[($nextIndex)] )
# So we dont repeat the last index add 1
$currentIndex = $nextIndex + 1
}
# Print rules
$rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment