Abbreviations, automatic: Difference between revisions
Content deleted Content added
SqrtNegInf (talk | contribs) Added Perl example |
SqrtNegInf (talk | contribs) m →{{header|Perl 6}}: rearrange for loop to align 'return' conditions |
||
Line 866: | Line 866: | ||
<lang perl6>sub auto-abbreviate ( Str $string ) { |
<lang perl6>sub auto-abbreviate ( Str $string ) { |
||
return Nil unless my @words = $string.words; |
return Nil unless my @words = $string.words; |
||
return $_ if @words».substr(0, $_).Set == @words for 1 .. @words».chars.max; |
|||
return '∞'; |
|||
return $_ if @words».substr(0, $_).Set == @words; |
|||
return '∞' if $_ == $max; |
|||
} |
|||
} |
} |
||