Skip to content

Commit 48bc232

Browse files
committed
Fix ext extraction to use lastDotIndex for accurate file extension
1 parent 5bbf762 commit 48bc232

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
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+
const lastDotIndex = base.lastIndexOf(".");
1516
//console.log(`The base part of ${filePath} is ${base}`);
1617

1718
// Create a variable to store the dir part of the filePath variable
1819
// Create a variable to store the ext part of the variable
1920

2021
const dir = filePath.slice(0, lastSlashIndex);
21-
const ext = base.slice(-4);
22+
const ext = base.slice(lastDotIndex);
2223
//console.log(dir);
2324
//console.log(ext);
2425

0 commit comments

Comments
 (0)