Created
June 3, 2015 08:15
-
-
Save gilligan/48e451b79e709079c656 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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