Pangram checker: Difference between revisions
Content added Content deleted
(unnecessary call to asMutable removed) |
(Replaced PowerShell with multiple, simpler examples) |
||
Line 1,744: | Line 1,744: | ||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
Cyrillic test sample borrowed from Perl 6. |
|||
⚫ | |||
<lang PowerShell> |
<lang PowerShell> |
||
function Test-Pangram |
function Test-Pangram ( [string]$Text, [string]$Alphabet = 'abcdefghijklmnopqrstuvwxyz' ) |
||
{ |
|||
[OutputType([bool])] |
|||
⚫ | |||
⚫ | |||
[Parameter(Mandatory=$true, |
|||
Position=0)] |
|||
[string] |
|||
$String |
|||
) |
|||
if ($String.Length -lt 26) {return $false} |
|||
[char[]]$alphabet = "abcdefghijklmnopqrstuvwxyz".ToCharArray() |
|||
[char[]]$inputStr = $String.ToCharArray() |
|||
foreach ($letter in $alphabet) |
|||
{ |
{ |
||
$Text = $Text.ToLower() |
|||
if ($letter -notin $inputStr) {return $false} |
|||
$Alphabet = $Alphabet.ToLower() |
|||
$IsPangram = $Alphabet.ToCharArray().Where{ $Text.Contains( $_ ) }.Count -eq $Alphabet.Length |
|||
⚫ | |||
} |
} |
||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
Test-Pangram 'Съешь же ещё этих мягких французских булок, да выпей чаю' 'абвгдежзийклмнопрстуфхцчшщъыьэюяё' |
|||
</lang> |
</lang> |
||
⚫ | |||
A way the function Test-Pangram might be used: |
|||
⚫ | |||
$letters = [regex]'[A-Za-z]' |
|||
⚫ | |||
"Pack my box with five dozen liquor jugs.", |
|||
"Jackdaws love my big sphinx of quartz.", |
|||
"The five boxing wizards jump quickly.", |
|||
"How vexingly quick daft zebras jump!", |
|||
"Bright vixens jump; dozy fowl quack.", |
|||
"My dog has fleas." | ForEach-Object { |
|||
[PSCustomObject]@{ |
|||
String = $_ |
|||
Letters = $letters.Matches($_).Count |
|||
IsPangram = Test-Pangram -String $_ |
|||
} |
|||
} |
|||
$candidates |
|||
</lang> |
|||
⚫ | |||
<pre> |
<pre> |
||
False |
|||
String Letters IsPangram |
|||
True |
|||
------ ------- --------- |
|||
True |
|||
The quick brown fox jumps over the lazy dog. 35 True |
|||
Pack my box with five dozen liquor jugs. 32 True |
|||
Jackdaws love my big sphinx of quartz. 31 True |
|||
The five boxing wizards jump quickly. 31 True |
|||
How vexingly quick daft zebras jump! 30 True |
|||
Bright vixens jump; dozy fowl quack. 29 True |
|||
My dog has fleas. 13 False |
|||
</pre> |
</pre> |
||
{{works with|PowerShell|2}} |
|||
Filter the list to contain only pangrams sorted by letter count: |
|||
<lang PowerShell> |
<lang PowerShell> |
||
function Test-Pangram ( [string]$Text, [string]$Alphabet = 'abcdefghijklmnopqrstuvwxyz' ) |
|||
$pangrams = $candidates | Where-Object -Property IsPangram -EQ $true | |
|||
⚫ | |||
Select-Object -Property String, Letters | |
|||
$Text = $Text.ToLower() |
|||
Sort-Object -Property Letters |
|||
$Alphabet = $Alphabet.ToLower() |
|||
$pangrams |
|||
$IsPangram = ( $Alphabet.ToCharArray() | Where { $Text.Contains( $_ ) } ).Count -eq $Alphabet.Length |
|||
return $IsPangram |
|||
⚫ | |||
⚫ | |||
Test-Pangram 'The quick brown fox jumps over the lazy dog.' |
|||
Test-Pangram 'Съешь же ещё этих мягких французских булок, да выпей чаю' 'абвгдежзийклмнопрстуфхцчшщъыьэюяё' |
|||
</lang> |
</lang> |
||
{{ |
{{out}} |
||
<pre> |
<pre> |
||
False |
|||
String Letters |
|||
True |
|||
------ ------- |
|||
True |
|||
Bright vixens jump; dozy fowl quack. 29 |
|||
How vexingly quick daft zebras jump! 30 |
|||
The five boxing wizards jump quickly. 31 |
|||
Jackdaws love my big sphinx of quartz. 31 |
|||
Pack my box with five dozen liquor jugs. 32 |
|||
⚫ | |||
</pre> |
</pre> |
||