Compare length of two strings: Difference between revisions

added Emacs Lisp code to order strings by length
(added Emacs Lisp code to order strings by length)
Line 1,265:
scmp "Rosetta" "Code"
</syntaxhighlight>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">
(defun sort-list-by-string-length (list-of-strings)
"Take list of strings and order from longest to shortest."
(sort list-of-strings 'longer-string)) ; uses "longer-string" function below for sort order
 
(defun longer-string (string-1 string-2)
"Test if STRING-1 is longer than STRING-2."
(> (length string-1) (length string-2))) ; is STRING-1 longer than STRING-2?
</syntaxhighlight>
{{out}}
(sort-list-by-string-length '("abcd" "123456789" "abcdef" "1234567"))
<pre>
("123456789" "1234567" "abcdef" "abcd")
</pre>
 
=={{header|EMal}}==
29

edits