or

function simplifyPath(path) { const stack = []; const pathes = path.split('/').filter(p => p && p !== '.'); pathes.map(p => p === '..' ? stack.pop() : stack.push(p)); return '/' + stack.join('/'); }