Jump to content

Longest common prefix: Difference between revisions

m
m (→‎{{header|Phix}}: added syntax colouring, marked p2js compatible)
Line 1,288:
 
<lang dyalect>func lcp(sa...) {
if sa.lenLength() == 0 || !sa[0] {
return ""
}
 
var ret = ""
var idx = 0
 
while true {
var thisLetter = '\0'
for word in sa {
if idx == word.lenLength() {
return ret
}
Line 1,308:
}
}
 
ret += thisLetter
idx += 1
}
}
 
print(lcp("interspecies", "interstellar", "interstate"))
print(lcp("throne", "throne"))
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.