Skip to content

Commit 1f01abe

Browse files
committed
done exercises paths.js
1 parent bcff939 commit 1f01abe

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Sprint-1/exercises/paths.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,28 @@
99

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

12+
/* ================ lastIndexOf() ===================
13+
-we use this to obtain the last position of / where is located the File.txt
14+
-const base = filePath.slice(lastSlashIndex + 1); with + 1 we start to subtract after /
15+
Index: 0 1 2 ... 37 38 39 40 41 42
16+
filePath: / U s ... / f i l e .txt
17+
-
18+
*/
19+
1220
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
1321
const lastSlashIndex = filePath.lastIndexOf("/");
22+
console.log(lastSlashIndex); // 44
1423
const base = filePath.slice(lastSlashIndex + 1);
15-
console.log(`The base part of ${filePath} is ${base}`);
24+
console.log(base); // file.txt
25+
// console.log(`The base part of ${filePath} is ${base}`);
1626

1727
// Create a variable to store the dir part of the filePath variable
18-
// Create a variable to store the ext part of the variable
28+
const lastDotIndex = filePath.lastIndexOf(".");
29+
console.log(lastDotIndex); // index position 49
30+
const extractDir = filePath.slice(0, lastDotIndex);
31+
console.log(`Directory and filename (without extension) ${extractDir}`);
32+
33+
34+
// Create a variable to store the ext part of the variable"
35+
const extensionName = filePath.slice(lastDotIndex + 1);
36+
console.log(`extension: ${extensionName}`); // txt

0 commit comments

Comments
 (0)