Compare length of two strings: Difference between revisions

Add Factor
(Added EasyLang implementation and moved BASIC)
(Add Factor)
Line 663:
"Rosetta" (length: 7)
"Code" (length: 4)
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
<syntaxhighlight lang=factor>USING: formatting io kernel qw sequences sorting ;
 
: .length ( str -- ) dup length "%u has length %d\n" printf ;
 
"I am a string" "I am a string too"
[ longer .length ] [ shorter .length ] 2bi nl
 
qw{ abcd 123456789 abcdef 1234567 } dup [ length ] inv-sort-with
"%u sorted by descending length:\n%u\n" printf</syntaxhighlight>
{{out}}
<pre>
"I am a string too" has length 17
"I am a string" has length 13
 
{ "abcd" "123456789" "abcdef" "1234567" } sorted by descending length:
{ "123456789" "1234567" "abcdef" "abcd" }
</pre>
 
1,808

edits