Skip to content

Commit d17fa1d

Browse files
committed
update: Implement dir and ext extraction logic in 3-paths.js
1 parent 729f88f commit d17fa1d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ console.log(`The base part of ${filePath} is ${base}`);
1717
// Create a variable to store the dir part of the filePath variable
1818
// Create a variable to store the ext part of the variable
1919

20-
const dir = ;
21-
const ext = ;
22-
23-
// https://www.google.com/search?q=slice+mdn
20+
const dir = filePath.slice(0, lastSlashIndex);// The code uses the lastIndexOf method to find the position of the last slash in;
21+
console.log(`The dir part of ${filePath} is ${dir}`);
22+
filePath.slice(0, lastSlashIndex);
23+
const ext = filePath;
24+
filePath
25+
.slice(lastSlashIndex + 1)
26+
.split(".")
27+
.pop();
28+
// The code above uses the lastIndexOf method to find the position of the last slash in the filePath string.
29+
// The slice method is then used to extract the base part of the filePath string, which is the part after the last slash.

0 commit comments

Comments
 (0)