Skip to content

Commit 1f147eb

Browse files
3-paths.js fixing
1 parent 041e4fc commit 1f147eb

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

Sprint-1/1-key-exercises/3-paths.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,10 @@ const ext =filePath.slice(slashIndex + 49, 53);
2323
console.log(`The dir part of ${filePath} is ${dir}`);
2424
console.log(`The ext part of ${filePath} is ${ext}`);
2525
*/
26-
27-
function pathFinder(userInput, filePath){
28-
// 1. Check if the user input exists inside the full path
29-
if (!fullPath.includes(userInput)) {
30-
console.log("Input not found in path");
31-
return;
32-
}
33-
34-
// 2. Split the path into parts
35-
const parts = filePath.split("/");
36-
37-
// 3. Base = last element
38-
const base = parts[parts.length - 1];
39-
40-
// 4. Dir = everything except the last element
41-
const dir = parts.slice(0, parts.length - 1).join("/");
42-
43-
// 5. Extension logic
44-
const dotIndex = base.lastIndexOf(".");
45-
const ext = dotIndex === -1 ? "" : base.slice(dotIndex);
46-
47-
// 6. Print everything
48-
console.log(`Full path: ${filePath}`);
49-
console.log(`Directory: ${dir}`);
50-
console.log(`Base: ${base}`);
51-
console.log(`Extension: ${ext}`);
52-
53-
}
54-
55-
console.log(pathFinder(filePath));
26+
27+
let dirDirectory = filePath.slice(filePath.indexOf("/"),filePath.lastIndexOf("/"));
28+
let extDirectory = filePath.slice(filePath.lastIndexOf("/"));
29+
console.log(`The dir part of the file is ${dirDirectory}.`);
30+
console.log(`The ext part of the file is ${extDirectory}.`);
5631

5732
// https://www.google.com/search?q=slice+mdn

0 commit comments

Comments
 (0)