This version walks forward char by char. Is there a nim equivalent to Python's
`timeit` module for timing snippets?
proc commonPrefix*(paths: openArray[string], sep = "/"): string =
if len(paths) == 0:
return ""
result = paths[0]
var index = 0
var ok = false
for path in paths[1 .. ^1]:
while index < len(path) and index < len(result) and
result[index] == path[index]:
inc index
ok = true
result = if not ok:
""
else:
result[0 .. result.rfind(sep, 0, index)]
Run
- A path commonPrefix function marks
- Re: A path commonPrefix function SolitudeSF
- Re: A path commonPrefix function demotomohiro
- Re: A path commonPrefix function marks
