-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest3.js
More file actions
38 lines (35 loc) · 761 Bytes
/
test3.js
File metadata and controls
38 lines (35 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function solution(paths) {
var answer = '';
const allPaths = findAllPath(paths);
console.log(allPaths);
const stack = [];
for(ap of allPaths) {
if(ap[0] == '.'){
let removeCnt = ap.length - 1;
while(removeCnt--){
stack.pop();
}
}
else if(ap!=='') {
stack.push(ap);
}
console.log(stack);
}
for(s of stack) {
answer+="/";
answer+=s;
}
return answer;
}
function findAllPath(paths) {
let newPaths = [];
//let curP;
for(p of paths) {
newPaths = newPaths.concat(p.split('/'));
console.log('p: ', p);
console.log(p.split('/'));
}
return newPaths;
}
console.log(solution(
["/foo", "bar", "baz/asdf", "q", ".."]));