I didn't knew myself we could do that with the String.prototype.match method. Not only this is easier, but it is also faster (at least for Google Chrome) than what I did with the Array.prototype.reduce method.
But I guess we could simplify the RegExp and the fuction to one line if we wanted to to aggressive optimizations.
Hi Matt and thanks for your answer.
I didn't knew myself we could do that with the
String.prototype.match
method. Not only this is easier, but it is also faster (at least for Google Chrome) than what I did with theArray.prototype.reduce
method.But I guess we could simplify the RegExp and the fuction to one line if we wanted to to aggressive optimizations.
Since it does not need to check for characters before the slash (in this case since we are matching a UNIX absolute path).