Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Given an array of path strings, find the longest common prefix path.
- def find_base_path(paths)
- return paths.first if paths.length <= 1
- arr = paths.sort
- f = arr.first.split('/')
- l = arr.last.split('/')
- i = 0
- i += 1 while f[i] == l[i] && i <= f.length
- f.slice(0, i).join('/')
- end
Add Comment
Please, Sign In to add comment