Given an array of
['/a','/a/b/c/d/e','/b','/b/c','/a/b/c/d','/a','/b']
I would like to be able to reduce this array down to:
['/a/b/c/d/e','/b/c']
i.e the longest of each unique path ('/a'
is a substring of '/a/b/c/d/e'
)
Perhaps I don't know the correct terminology, but I've been Googling for a couple of hours and have gotten nowhere
I was thinking of sorting by element length, then for each element loop through the list, checking the indexOf()
until I reached the element itself
Just seems kind of expensive.
edit I didn't explain that well enough - the strings are paths - and I need to use mkdirp to create the directory structure, but didn't want to call it many times (mkdir /a/b/c/d/e will create /a/b/c , so if I have another path of /a/b/c I just want to ignore it