Abbreviations, automatic: Difference between revisions

m
→‎{{header|Perl 6}}: rearrange for loop to align 'return' conditions
(Added Perl example)
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;
}
}
 
2,392

edits