Skip to content

Commit e2994d8

Browse files
committed
Fix dir variable by taking root, leaving out last / by using lastSlashIndex. Fix ext variable by using lastIndexOf, which works if filepath has more than one .
1 parent 59faf6f commit e2994d8

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ 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 = filePath.slice(1, filePath.indexOf(base));
21-
const ext = filePath.slice(-(filePath.length - filePath.indexOf(".")));
22-
console.log(dir);
20+
const dir = filePath.slice(0, lastSlashIndex);
21+
const ext = filePath.slice(filePath.lastIndexOf("."));
2322

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

0 commit comments

Comments
 (0)