Skip to content

Commit 1030764

Browse files
committed
Fix code to correctly extract the .txt file extension
- Use lastIndexOf('.') and slice() to return '.txt'
1 parent 095a3ea commit 1030764

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ console.log(`The base part of ${filePath} is ${base}`);
2020

2121
const dir = filePath.slice(0,lastSlashIndex) ;
2222
console.log(dir);
23-
const ext = filePath.slice(lastSlashIndex + 1) ;
23+
const lastDotIndex = base.lastIndexOf(".");
24+
console.log(lastDotIndex);
25+
const ext = base.slice(lastDotIndex) ;
2426
console.log(ext);
2527

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

0 commit comments

Comments
 (0)