N'th: Difference between revisions
→{{header|PowerShell}}: Fixed 11th, 112th and 13th
(→{{header|Batch File}}: Fixed 11tth, 12th and 13th) |
(→{{header|PowerShell}}: Fixed 11th, 112th and 13th) |
||
Line 3,207:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
function nth($inp){
default{
switch($inp % 10){
return "$inp$suffix "▼
1{$suffix="st"}
2{$suffix="nd"}
3{$suffix="rd"}
}
}
}
0..25 | %{Write-host -nonewline (nth "$_")};""
250..265 | %{Write-host -nonewline (nth "$_")};""
1000..1025 | %{Write-host -nonewline (nth "$_")};""
</syntaxhighlight>
{{Out}}
<pre>
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th
</pre>
===An Alternate Version===
Line 3,233 ⟶ 3,244:
$suffix = "th"
switch ($Number %
11 {$suffix = "th"}
▲ {
switch ($Number % 10){
1 {$suffix = "st"}
2 {$suffix = "nd"}
3 {$suffix = "rd"}
}
}
}
Line 3,249 ⟶ 3,266:
{{Out}}
<pre>
1st
6th
16th
21st
251st
256th
261st
1001st
1006th
1016th
1021st
</pre>
|