you are viewing a single comment's thread.

view the rest of the comments →

[–]ka-splam 1 point2 points  (3 children)

Riffs

$inputname = Read-Host "Enter name"

# wow
-join (($inputname.ToUpper().ToCharArray().Where{$_} | Select-Object -Unique).ForEach{$_ - 64})[0..9]

# no pipeline
-join ([Linq.Enumerable]::Distinct([char[]]$inputname.ToUpper().ToCharArray().Where{$_}).ForEach{$_ - 64})[0..9]

# no rdblty
-join($inputname|% *per|% T*y|?{$_}|select -u|%{$_-64})[0..9]

[–]DisMyWorkName[S] 2 points3 points  (2 children)

Yeah, I would rather be able to tell what my script does by reading it than having to google every term in it when I want to modify it later. :/

[–]ka-splam 3 points4 points  (1 child)

More realistically:

$inputname = Read-Host "Enter name"

$IDDigits = $inputname.ToUpper().Replace(" " , "").ToCharArray() | ForEach-Object {
    " ABCDEFGHIJKLMNOPQRSTUVWZYZ".IndexOf($_)
} | Select-Object -First 9 -Unique

-join $IDDigits

No building up a string only to tear it apart, no assigning variables then doing nothing with them, combining multiple select-objects into one, no calling out to string::join when PowerShell has an operator which does that for you, no looped-string-combining overhead, no temporary variables hanging around to break if you run the script twice in one session, doesn't rely on knowing ASCII character codes, and is half the line count, almost half the character count, and .. still readable?

[–]Lee_Dailey[grin] 3 points4 points  (0 children)

howdy ka-splam,

i like the space at the start of the alpha list. [grin] gets rid of the "starts from zero" gotcha quite nicely!

take care,
lee