Skip to content

Commit 03b641a

Browse files
author
russom
committed
Update code with lastIndexOf
1 parent 36f340d commit 03b641a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

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

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

2020
const dir = filePath.slice(0, lastSlashIndex);
21-
const ext = filePath.slice(filePath.length -3);
21+
const lastDotIndex = filePath.lastIndexOf(".");
22+
const ext = filePath.slice(lastDotIndex + 1);
2223

23-
console.log(dir);
24-
console.log(ext);
24+
console.log(`The dir part of ${filePath} is ${dir}`);
25+
console.log(`The ext part of ${filePath} is ${ext}`);
2526

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

0 commit comments

Comments
 (0)