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:
<lang perl6>sub auto-abbreviate ( Str $string ) {
return Nil unless my @words = $string.words;
myreturn $max_ if @words».substr(0, $_).Set == @words for 1 .. @words».chars.max;
forreturn 0 .. $max {'∞';
return $_ if @words».substr(0, $_).Set == @words;
return '∞' if $_ == $max;
}
}