[71] 简化路径
1 /** 2 * @param {string} path 3 * @return {string} 4 */ 5 var simplifyPath = function (path) { 6 const arr = path.split('/'); 7 const ans = []; 8 for (const item of arr) { 9 if (item === '..') { 10 ans.pop(); 11 } else if (item && item !== '.') { 12 ans.push(item); 13 } 14 } 15 return '/' + ans.join('/'); 16 };

浙公网安备 33010602011771号