Skip to content

Commit 538ff7d

Browse files
committed
updated ext variable to use the lastindexof method and explained why
1 parent ae092fd commit 538ff7d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
// (All spaces in the "" line should be ignored. They are purely for formatting.)
1111

12-
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
12+
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/photo/file.txt";
1313
const lastSlashIndex = filePath.lastIndexOf("/"); //44
1414
const base = filePath.slice(lastSlashIndex + 1); //file.txt
15-
//console.log(`The base part of ${filePath} is ${base}`);
15+
console.log(`The base part of ${filePath} is ${base}`);
1616

1717
const dir = filePath.slice(0, lastSlashIndex);
18-
const ext = filePath.slice(-4);
19-
console.log(dir);
18+
const ext = filePath.slice(filePath.lastIndexOf("."));
19+
//lastIndexOf() method works better here because it'll look for the last time "." appears in the file path which will always give the correct file ext instead of going a set number back with the slice() method i used previously which may not work for every file extension depending on it length. So now console.log will print .txt or .jpeg if that was the file ext
2020
console.log(ext);
2121
// https://www.google.com/search?q=slice+mdn

0 commit comments

Comments
 (0)