私は2つのパスの違いを取得しようとしています。私は解決策を持って来ましたが、それがうまくいても、それについて本当に幸せではありません。これを行うより良い/簡単な方法がありますか?2つのパス間のNodejsの差
var firstPath = '/my/first/path'
, secondPath = '/my/first/path/but/longer'
// what I want to get is: '/but/longer'
// my code:
var firstPathDeconstruct = firstPath.split(path.sep)
, secondPathDeconstruct = secondPath.split(path.sep)
, diff = []
secondPathDeconstruct.forEach(function(chunk) {
if (firstPathDeconstruct.indexOf(chunk) < 0) {
diff.push(chunk)
}
})
console.log(diff)
// output ['but', 'longer']
私は前にそれを見ていたし、いくつかの理由で、それは適切ではないと思いました。しかし、それはです。ありがとう – romainberger