标签:fun push lte spl for pop imp ret replace
/**
* @param {string} path
* @return {string}
*/
function simplifyPath(path) {
const pathArr = path.split('/').filter(item => item !== '');
const result = ['/'];
for (const i of pathArr) {
if (i === '..') {
if (result.length > 1) {
result.pop();
}
} else if (i !== '.') {
result.push(i);
}
}
return result.join('/').replace(/^\/{2,}/g, '/').replace(/\/+$/g, '').replace(/\/+/g, '/') || '/';
}
标签:fun push lte spl for pop imp ret replace
原文地址:https://www.cnblogs.com/rosendolu/p/10954589.html