Skip to content

Commit 4102ecb

Browse files
committed
Updating the answer
1 parent b21591e commit 4102ecb

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
// " / home/user/dir / file .txt "
66
// └──────┴──────────────┴──────┴─────┘
77

8-
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
98

10-
// Find the index of the last slash and the last dot
9+
10+
// all spaces in the "" line should be ignored. THey are purely for formatting.
11+
12+
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
1113
const lastSlashIndex = filePath.lastIndexOf("/");
12-
const lastDotIndex = filePath.lastIndexOf(".");
14+
const base = filePath.slice(lastSlashIndex + 1);
15+
console.log (the base part of ${filePath} is ${base});
16+
17+
// Create a variable to store the dir part of the filePath variable.
18+
// Create a variable to store the ext part of the variable.
1319

14-
// Extract each part
15-
const base = filePath.slice(lastSlashIndex + 1); // "file.txt"
16-
const dir = filePath.slice(0, lastSlashIndex); // "/Users/mitch/cyf/Module-JS1/week-1/interpret"
17-
const ext = filePath.slice(lastDotIndex + 1); // "txt"
20+
const dir = filePath.slice(lastSlashIndex+1)
21+
const ext = filePath.slice(lastDotIndexOf(".") +1);
1822

19-
console.log(`The dir part of ${filePath} is ${dir}`);
20-
console.log(`The base part of ${filePath} is ${base}`);
21-
console.log(`The ext part of ${filePath} is ${ext}`);
23+
console.log (dir)
24+
// https://www.google.com/search?q=slice+mdn

0 commit comments

Comments
 (0)