Skip to content

Commit f7799bb

Browse files
committed
feat: extract root, filename and extension using slice and lastIndexOf
1 parent 982f3b3 commit f7799bb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Sprint-1/exercises/paths.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@
1212
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
1313
const lastSlashIndex = filePath.lastIndexOf("/");
1414
const base = filePath.slice(lastSlashIndex + 1);
15-
console.log(`The base part of ${filePath} is ${base}`);
1615

1716
// Create a variable to store the dir part of the filePath variable
1817
// Create a variable to store the ext part of the variable
18+
19+
const lastDot = filePath.lastIndexOf(".");
20+
console.log(`The indexDot is ${lastDot}`);
21+
22+
const ext = filePath.slice(lastDot);
23+
24+
const fileName = filePath.slice(lastSlashIndex + 1, lastDot);
25+
const dir = filePath.slice(1, lastSlashIndex + 1);
26+
27+
28+
29+
console.log(`The dir is 👉 ${dir}`);
30+
console.log(`The nameFile is 👉 ${fileName}`);
31+
console.log(`The extension is 👉 ${ext}`);
32+
33+
34+

0 commit comments

Comments
 (0)