Jump to content

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===
'''(AppleScriptObjectiveC)'''
<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.
 
557

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.