Jump to content

Pangram checker: Difference between revisions

Replaced PowerShell with multiple, simpler examples
(unnecessary call to asMutable removed)
(Replaced PowerShell with multiple, simpler examples)
Line 1,744:
 
=={{header|PowerShell}}==
Cyrillic test sample borrowed from Perl 6.
<lang{{works with|PowerShell>|4}}
<lang PowerShell>
function Test-Pangram ( [string]$Text, [string]$Alphabet = 'abcdefghijklmnopqrstuvwxyz' )
{
[OutputType([bool])]
Param
(
[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
return $trueIsPangram
}
 
$candidatesTest-Pangram = "'The quick brown fox jumpsjumped over the lazy dog.",'
return $true
Test-Pangram 'The quick brown fox jumps over the lazy dog. 35'
}
Test-Pangram 'Съешь же ещё этих мягких французских булок, да выпей чаю' 'абвгдежзийклмнопрстуфхцчшщъыьэюяё'
</lang>
{{Outout}}
A way the function Test-Pangram might be used:
<lang PowerShell>
$letters = [regex]'[A-Za-z]'
 
$candidates = "The quick brown fox jumps over the lazy dog.",
"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>
{{Out}}
<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>
{{works with|PowerShell|2}}
Filter the list to contain only pangrams sorted by letter count:
<lang PowerShell>
function Test-Pangram ( [string]$Text, [string]$Alphabet = 'abcdefghijklmnopqrstuvwxyz' )
$pangrams = $candidates | Where-Object -Property IsPangram -EQ $true |
Param{
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 jumpsjumped over the lazy dog. 35 True'
Test-Pangram 'The quick brown fox jumps over the lazy dog.'
Test-Pangram 'Съешь же ещё этих мягких французских булок, да выпей чаю' 'абвгдежзийклмнопрстуфхцчшщъыьэюяё'
</lang>
{{Outout}}
<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
The quick brown fox jumps over the lazy dog. 35
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.