Skip to content

Commit

Permalink
Adjusting formatting
Browse files Browse the repository at this point in the history
Indentation on function
  • Loading branch information
AndrewDavis1191 authored Oct 7, 2020
1 parent d566d6f commit 33cd1f5
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions powershell.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -620,26 +620,27 @@ $area
$targetArray = 'a','b','c','d','e','f','g','h','i','j','k','l','m'
function Format-Range ($start, $end) {
[System.Collections.ArrayList]$firstSectionArray = @()
[System.Collections.ArrayList]$secondSectionArray = @()
[System.Collections.Stack]$stack = @()
for ($index = 0; $index -lt $targetArray.Count; $index++) {
function Format-Range ($start, $end, $array) {
[System.Collections.ArrayList]$firstSectionArray = @()
[System.Collections.ArrayList]$secondSectionArray = @()
[System.Collections.Stack]$stack = @()
for ($index = 0; $index -lt $array.Count; $index++) {
if ($index -lt $start) {
$firstSectionArray.Add($targetArray[$index]) > $null
$firstSectionArray.Add($array[$index]) > $null
}
elseif ($index -ge $start -and $index -le $end) {
$stack.Push($targetArray[$index])
$stack.Push($array[$index])
}
else {
$secondSectionArray.Add($targetArray[$index]) > $null
$secondSectionArray.Add($array[$index]) > $null
}
}
$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.
# It's also kind of lengthy.
Expand Down

0 comments on commit 33cd1f5

Please sign in to comment.