मैं दो पथ के बीच अंतर प्राप्त करने की कोशिश कर रहा हूं। मैं एक समाधान के साथ आया हूं, लेकिन मैं इसके बारे में वास्तव में खुश नहीं हूं, भले ही यह काम करता हो। क्या ऐसा करने के लिए एक बेहतर/आसान तरीका है?दो पथों के बीच नोडज अंतर
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