Skip to content

Instantly share code, notes, and snippets.

@gilligan
Created June 3, 2015 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilligan/48e451b79e709079c656 to your computer and use it in GitHub Desktop.
Save gilligan/48e451b79e709079c656 to your computer and use it in GitHub Desktop.
//
// stripPath('/foo/bar/baz', ['x', 'foo', 'bar']) => 'bar/baz'
//
var stripPath = λ(path, names) {
var f = R.flip(R.strLastIndexOf)(path);
var indexList = R.map( λ(name) {
return {
n: name,
pos: f(name)
};
}, names);
var cmp = function(x) {
return x.pos;
};
var lastComponent = R.maxBy(cmp, indexList);
return R.substringFrom(lastComponent.pos, path);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment