Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
3 Swapped to IndexOf and only one array indexing
source | link

PowerShell v2+, 59 58 5252 51 bytes

param($n)(($n+'\/'[$n[-1]-eq92])," $n","$n/","$n\")[$n[['.\/'.IndexOf($n[-1]-eq46])]

Takes input $n, dumps it into a pseudo-ternary (indexing into a dynamican array) index operation. We select the element of the array based on the index [$n[['.\/'.IndexOf($n[-1]-eq46]) (i-- i.e., if the last character is ASCII 46, a period). If it is a period, the indexing selects the second element, the " $n", which just prepends a space.

Otherwise, it selects the first element. Here we take $n and append the result of a string slice against '\/', this time selecting the appropriate slash based on the last elementcharacter of the input string (by comparing against 92$n, i.e., ASCII \). The Booleanthis will result of -eq is implicitly converted toin 0 or, 1, so this slices theor '\/'2. That corresponds to the appropriate string appropriatelyof the array.

  In eitherany case, the resulting string is left on the pipeline and printing is implicit.

Test cases

PS C:\Tools\Scripts\golfing> 0..7|%{' '*$_+'.'}|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
. =>  .
 . =>   .
  . =>    .
   . =>     .
    . =>      .
     . =>       .
      . =>        .
       . =>         .

PS C:\Tools\Scripts\golfing> '/,\,/\,\/,/\/,\/\,/\/\,\/\/'-split','|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
/ => /\
\ => \/
/\ => /\/
\/ => \/\
/\/ => /\/\
\/\ => \/\/
/\/\ => /\/\/
\/\/ => \/\/\

PowerShell v2+, 59 58 52 bytes

param($n)(($n+'\/'[$n[-1]-eq92])," $n")[$n[-1]-eq46]

Takes input $n, dumps it into a pseudo-ternary (indexing into a dynamic array) based on [$n[-1]-eq46] (i.e., if the last character is ASCII 46, a period). If it is a period, the indexing selects the second element, the " $n", which just prepends a space.

Otherwise, it selects the first element. Here we take $n and append the result of a string slice against '\/', this time selecting the appropriate slash based on the last element of the input string (by comparing against 92, i.e., ASCII \). The Boolean result of -eq is implicitly converted to 0 or 1, so this slices the '\/' string appropriately.

  In either case, the resulting string is left on the pipeline and printing is implicit.

Test cases

PS C:\Tools\Scripts\golfing> 0..7|%{' '*$_+'.'}|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
. =>  .
 . =>   .
  . =>    .
   . =>     .
    . =>      .
     . =>       .
      . =>        .
       . =>         .

PS C:\Tools\Scripts\golfing> '/,\,/\,\/,/\/,\/\,/\/\,\/\/'-split','|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
/ => /\
\ => \/
/\ => /\/
\/ => \/\
/\/ => /\/\
\/\ => \/\/
/\/\ => /\/\/
\/\/ => \/\/\

PowerShell v2+, 59 58 52 51 bytes

param($n)(" $n","$n/","$n\")['.\/'.IndexOf($n[-1])]

Takes input $n, dumps it an array index operation. We select the element of the array based on the index ['.\/'.IndexOf($n[-1]) -- i.e., based on the last character of the input $n, this will result in 0, 1, or 2. That corresponds to the appropriate string of the array. In any case, the resulting string is left on the pipeline and printing is implicit.

Test cases

PS C:\Tools\Scripts\golfing> 0..7|%{' '*$_+'.'}|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
. =>  .
 . =>   .
  . =>    .
   . =>     .
    . =>      .
     . =>       .
      . =>        .
       . =>         .

PS C:\Tools\Scripts\golfing> '/,\,/\,\/,/\/,\/\,/\/\,\/\/'-split','|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
/ => /\
\ => \/
/\ => /\/
\/ => \/\
/\/ => /\/\
\/\ => \/\/
/\/\ => /\/\/
\/\/ => \/\/\
2 Swapped the match for a literal equals ASCII 46, swapped the slash comparison for string slicing
source | link

PowerShell v2+, 59 5858 52 bytes

param($n)(($n+('\','$n+'\/')[$n['[$n[-1]-eq92])," $n")[$n[$n[-match'\.']1]-eq46]

Takes input $n, dumps it into a pseudo-ternary (indexing into a dynamic array) based on $n[$n[-match'\.'1]-eq46] (i.e., if the last character is ASCII 46, a period). If matchit is a literal period, itthe indexing selects the second element, the " $n", which just prepends a space. 

Otherwise, it selects the first element. Here we take $n and append the result of another a pseudo-ternarystring slice against '\/', this time selecting the appropriate slash based on the last element of the input string (by comparing against 92, i.e., ASCII \). The Boolean result of -eq is implicitly converted to 0 or 1, so this slices the '\/' string appropriately. 

In either case, the resulting string is left on the pipeline and printing is implicit.

Test cases

PS C:\Tools\Scripts\golfing> 0..7|%{' '*$_+'.'}|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
. =>  .
 . =>   .
  . =>    .
   . =>     .
    . =>      .
     . =>       .
      . =>        .
       . =>         .

PS C:\Tools\Scripts\golfing> '/,\,/\,\/,/\/,\/\,/\/\,\/\/'-split','|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
/ => /\
\ => \/
/\ => /\/
\/ => \/\
/\/ => /\/\
\/\ => \/\/
/\/\ => /\/\/
\/\/ => \/\/\

PowerShell v2+, 59 58 bytes

param($n)(($n+('\','/')[$n[-1]-eq92])," $n")[$n-match'\.']

Takes input $n, dumps it into a pseudo-ternary (indexing into a dynamic array) based on $n-match'\.'. If match a literal period, it selects the second element, the " $n", which just prepends a space. Otherwise, it selects the first element. Here we take $n and append the result of another a pseudo-ternary, this time selecting the appropriate slash based on the last element of the input string (by comparing against 92, i.e., ASCII \). In either case, the resulting string is left on the pipeline and printing is implicit.

Test cases

PS C:\Tools\Scripts\golfing> 0..7|%{' '*$_+'.'}|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
. =>  .
 . =>   .
  . =>    .
   . =>     .
    . =>      .
     . =>       .
      . =>        .
       . =>         .

PS C:\Tools\Scripts\golfing> '/,\,/\,\/,/\/,\/\,/\/\,\/\/'-split','|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
/ => /\
\ => \/
/\ => /\/
\/ => \/\
/\/ => /\/\
\/\ => \/\/
/\/\ => /\/\/
\/\/ => \/\/\

PowerShell v2+, 59 58 52 bytes

param($n)(($n+'\/'[$n[-1]-eq92])," $n")[$n[-1]-eq46]

Takes input $n, dumps it into a pseudo-ternary (indexing into a dynamic array) based on [$n[-1]-eq46] (i.e., if the last character is ASCII 46, a period). If it is a period, the indexing selects the second element, the " $n", which just prepends a space. 

Otherwise, it selects the first element. Here we take $n and append the result of a string slice against '\/', this time selecting the appropriate slash based on the last element of the input string (by comparing against 92, i.e., ASCII \). The Boolean result of -eq is implicitly converted to 0 or 1, so this slices the '\/' string appropriately. 

In either case, the resulting string is left on the pipeline and printing is implicit.

Test cases

PS C:\Tools\Scripts\golfing> 0..7|%{' '*$_+'.'}|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
. =>  .
 . =>   .
  . =>    .
   . =>     .
    . =>      .
     . =>       .
      . =>        .
       . =>         .

PS C:\Tools\Scripts\golfing> '/,\,/\,\/,/\/,\/\,/\/\,\/\/'-split','|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
/ => /\
\ => \/
/\ => /\/
\/ => \/\
/\/ => /\/\
\/\ => \/\/
/\/\ => /\/\/
\/\/ => \/\/\
1
source | link

PowerShell v2+, 59 58 bytes

param($n)(($n+('\','/')[$n[-1]-eq92])," $n")[$n-match'\.']

Takes input $n, dumps it into a pseudo-ternary (indexing into a dynamic array) based on $n-match'\.'. If match a literal period, it selects the second element, the " $n", which just prepends a space. Otherwise, it selects the first element. Here we take $n and append the result of another a pseudo-ternary, this time selecting the appropriate slash based on the last element of the input string (by comparing against 92, i.e., ASCII \). In either case, the resulting string is left on the pipeline and printing is implicit.

Test cases

PS C:\Tools\Scripts\golfing> 0..7|%{' '*$_+'.'}|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
. =>  .
 . =>   .
  . =>    .
   . =>     .
    . =>      .
     . =>       .
      . =>        .
       . =>         .

PS C:\Tools\Scripts\golfing> '/,\,/\,\/,/\/,\/\,/\/\,\/\/'-split','|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
/ => /\
\ => \/
/\ => /\/
\/ => \/\
/\/ => /\/\
\/\ => \/\/
/\/\ => /\/\/
\/\/ => \/\/\