mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Adjusting formatting
Indentation on function
This commit is contained in:
parent
d566d6f3c9
commit
33cd1f57ef
@ -620,26 +620,27 @@ $area
|
|||||||
|
|
||||||
$targetArray = 'a','b','c','d','e','f','g','h','i','j','k','l','m'
|
$targetArray = 'a','b','c','d','e','f','g','h','i','j','k','l','m'
|
||||||
|
|
||||||
function Format-Range ($start, $end) {
|
function Format-Range ($start, $end, $array) {
|
||||||
[System.Collections.ArrayList]$firstSectionArray = @()
|
[System.Collections.ArrayList]$firstSectionArray = @()
|
||||||
[System.Collections.ArrayList]$secondSectionArray = @()
|
[System.Collections.ArrayList]$secondSectionArray = @()
|
||||||
[System.Collections.Stack]$stack = @()
|
[System.Collections.Stack]$stack = @()
|
||||||
for ($index = 0; $index -lt $targetArray.Count; $index++) {
|
for ($index = 0; $index -lt $array.Count; $index++) {
|
||||||
if ($index -lt $start) {
|
if ($index -lt $start) {
|
||||||
$firstSectionArray.Add($targetArray[$index]) > $null
|
$firstSectionArray.Add($array[$index]) > $null
|
||||||
}
|
}
|
||||||
elseif ($index -ge $start -and $index -le $end) {
|
elseif ($index -ge $start -and $index -le $end) {
|
||||||
$stack.Push($targetArray[$index])
|
$stack.Push($array[$index])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$secondSectionArray.Add($targetArray[$index]) > $null
|
$secondSectionArray.Add($array[$index]) > $null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$finalArray = $firstSectionArray + $stack.ToArray() + $secondSectionArray
|
$finalArray = $firstSectionArray + $stack.ToArray() + $secondSectionArray
|
||||||
Write-Output $finalArray
|
return $finalArray
|
||||||
}
|
}
|
||||||
|
|
||||||
Format-Range 2 6 # => 'a','b','g','f','e','d','c','h','i','j','k','l','m'
|
Format-Range 2 6 $targetArray
|
||||||
|
# => 'a','b','g','f','e','d','c','h','i','j','k','l','m'
|
||||||
|
|
||||||
# The previous method works, but uses extra memory by allocating new arrays.
|
# The previous method works, but uses extra memory by allocating new arrays.
|
||||||
# It's also kind of lengthy.
|
# It's also kind of lengthy.
|
||||||
|
Loading…
Reference in New Issue
Block a user