1 var aPath = 'C:/programfiles/game/a'
2 var bPath = 'C:/workspace/QQ/game/b'
3 function positivePath(a, b) {
4 var aArr = a.split('/')
5 var bArr = b.split('/')
6 for (var i = 0; i < aArr.length - 2; i++) {
7 if (bArr[i] != aArr[i]) {
8 bArr.splice(0,i)
9 return '../'.repeat(aArr.length - i) + bArr.join('/')
10 }
11 }
12 }
13 console.log(positivePath(aPath, bPath))