Skip to content

Commit 2fc4c90

Browse files
authored
Update 3-paths.js
1 parent 2f5a89b commit 2fc4c90

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@
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-
console.log(`The base part of ${filePath} is ${base}`);
1615

17-
// Create a variable to store the dir part of the filePath variable
1816
// Create a variable to store the ext part of the variable
19-
20-
const dir = filePath;
17+
const ext=base.slice(base.lastIndexOf(".") + 1); // The code uses the lastIndexOf method to find the position of the last dot in the base variable.
18+
// Create a variable to store the dir part of the filePath variable
19+
const dir = filePath.slice(0, lastSlashIndex);// The code uses the lastIndexOf method to find the position of the last slash in;
2120
filePath.slice(0, lastSlashIndex);
22-
const ext = filePath;
2321
filePath
2422
.slice(lastSlashIndex + 1)
2523
.split(".")
2624
.pop();
27-
// The code above uses the lastIndexOf method to find the position of the last slash in the filePath string.
28-
// The slice method is then used to extract the base part of the filePath string, which is the part after the last slash.
29-
30-
// https://www.google.com/search?q=slice+mdn
25+
console.log(`The dir part of ${filePath} is ${dir}`);
26+
console.log(`The base part of ${filePath} is ${base}`);
27+
console.log(`The ext part of ${filePath} is ${ext}`);

0 commit comments

Comments
 (0)