#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Find_common_directory_path#Sidef
#

var dirs = %w(
    /home/user1/tmp/coverage/test
    /home/user1/tmp/covert/operator
    /home/user1/tmp/coven/members
);

var unique_pref = dirs.map{.split('/')}.uniq_prefs.min_by{.len};
var common_dir  = [unique_pref, unique_pref.pop][0].join('/');
say common_dir;   # => /home/user1/tmp


assert_eq(common_dir, '/home/user1/tmp');
