Last active
June 4, 2020 14:24
-
-
Save ThePSAdmin/b5fbe87503dda843f5855b0f5de5c62b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
((((99..1)+'no more')|%{}{$y,$a=" on the wall"," bottle$(,'s'[$_-eq1]) of beer" | |
"Take one down and pass it around, $_$a$y.`n" | |
"$_$a$y, $_$a."-replace'^n',"N"}{"Go to the store and buy some more, 99$a$y."})[1..200])|write-host |
PalmEmanuel
commented
Jun 4, 2020
Nice! You can shorten the code somewhat by using -Begin -Process -End params of foreach-object positionally and assigning vars on the same line:
$b,$w,$n=' bottles of beer',' on the wall','o more'
99..1|%{}{("$_$b$w, $_$b.`nTake one down and pass it around, $($_-1)$b$w.`n"-replace' 0'," n$n")-replace'(\b1 \w+)s','$1'}{"N$n$b$w, n$n$b.`nGo to the store and buy some more, 99$b$w."}|write-host
That's clever! You took mine down below 250 as well!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment