Explodes a flat array of files into a tree in Javascript