Guest User

Untitled

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. # Given an array of path strings, find the longest common prefix path.
  2. def find_base_path(paths)
  3. return paths.first if paths.length <= 1
  4. arr = paths.sort
  5. f = arr.first.split('/')
  6. l = arr.last.split('/')
  7. i = 0
  8. i += 1 while f[i] == l[i] && i <= f.length
  9. f.slice(0, i).join('/')
  10. end
Add Comment
Please, Sign In to add comment