Longest common prefix: Difference between revisions
m
→{{header|AppleScript}}: Restored missing comment indicator, inserted separator, added index subheadings.
m (→version 2: added whitespace.) |
m (→{{header|AppleScript}}: Restored missing comment indicator, inserted separator, added index subheadings.) |
||
Line 237:
=={{header|AppleScript}}==
===AppleScriptObjC===
<lang applescript>use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
Line 261:
end longestCommonPrefix
--- Tests:
longestCommonPrefix({"interspecies", "interstellar", "interstate"}) --> "inters"
longestCommonPrefix({"throne", "throne"}) --> "throne"
Line 270:
longestCommonPrefix({"prefix", "suffix"}) --> ""
longestCommonPrefix({"foo", "foobar"}) --> "foo"</lang>
----
===Functional===
and for a functional definition (rather than a procedure) we can compose reusable generics, applying a ''takeWhile'' function (with a suitable predicate) to a transposed matrix of the characters in the given words.
|