Longest common prefix: Difference between revisions
Content added Content deleted
m (→version 2: added whitespace.) |
m (→{{header|AppleScript}}: Restored missing comment indicator, inserted separator, added index subheadings.) |
||
Line 237: | Line 237: | ||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
===AppleScriptObjC=== |
|||
'''(AppleScriptObjectiveC)''' |
|||
<lang applescript>use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later |
<lang applescript>use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later |
||
use framework "Foundation" |
use framework "Foundation" |
||
Line 261: | Line 261: | ||
end longestCommonPrefix |
end longestCommonPrefix |
||
Tests: |
--- Tests: |
||
longestCommonPrefix({"interspecies", "interstellar", "interstate"}) --> "inters" |
longestCommonPrefix({"interspecies", "interstellar", "interstate"}) --> "inters" |
||
longestCommonPrefix({"throne", "throne"}) --> "throne" |
longestCommonPrefix({"throne", "throne"}) --> "throne" |
||
Line 270: | Line 270: | ||
longestCommonPrefix({"prefix", "suffix"}) --> "" |
longestCommonPrefix({"prefix", "suffix"}) --> "" |
||
longestCommonPrefix({"foo", "foobar"}) --> "foo"</lang> |
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. |
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. |
||