It will automatically center to the specified line width, and requires that the line be at least as wide as the diamond itself.
function show-diamond { param( [ValidateScript( {$_ -ge 11} )] [int]$LineWidth = 11 ) $range = [System.Collections.Generic.List[int]]::new() (1..11).Where{$_ % 2 -gt 0} | ForEach-Object { $range.Add($_) } (9..1).Where{$_ % 2 -gt 0} | ForEach-Object { $range.Add($_) } $output = [System.Collections.Generic.List[string]]::new() for ($i = 0; $i -lt $range.Count; $i++) { $MidPoint = [math]::Round(($LineWidth - $range[$i]) / 2, [System.MidpointRounding]::AwayFromZero) $String = '{0}{1}' -f (' ' * $MidPoint), ('*' * $range[$i]) $output.Add($string) } $output }
David F.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Powershell
It will automatically center to the specified line width, and requires that the line be at least as wide as the diamond itself.
David F.