Jump to content

Longest common prefix: Difference between revisions

m
(→‎{{header|zkl}}: Added solution)
Line 39:
<lang zkl>fcn lcp(s,strings){ s[0,s.prefix(vm.pasteArgs(1))] }</lang>
Or, without using prefix:
{{trans|Scala}}
<lang zkl>fcn lcp(strings){
vm.arglist.reduce(fcn(prefix,s){ Utils.Helpers.zipW(prefix,s) // lazy zip
.pump(String,fcn([(a,b)]){ a==b and a or Void.Stop })
})
Line 52 ⟶ 53:
tester.testRun(lcp.fp("prefix","suffix"),Void,"",__LINE__);
tester.stats();</lang>
The fp (partial application) method is used to delay running lcp until tUtils.Helpers.zipW("fooz","foobar").pump(String,fcn([(a,b)]){a==b andthe atester oractually Voidtests.Stop})
he tester actually tests.
{{out}}
<pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.