Skip to content

Commit 1cf24f7

Browse files
authored
Refactor file path handling and enhance comments
Refactor file path manipulation code and improve comments.
1 parent 94e8a72 commit 1cf24f7

1 file changed

Lines changed: 9 additions & 33 deletions

File tree

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

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,28 @@
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";
13-
//const lastSlashIndex = 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
19-
20-
21-
//const dir = ;
22-
//const ext = ;
23-
24-
// https://www.google.com/search?q=slice+mdn
25-
26-
// from here start my explaination of the code I see for education purposes.
27-
// this is a file system that allows users to manipulate what files they see and what information they omit, and they use string
28-
//methods to do that
29-
// most common methods developers use to manipulate the files are included in this file Sprint-2\1-key-exercises\manipulating files.txt
30-
31-
// in this example the string methods are used to manipulate the file system
32-
3312
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
34-
// a variable is created to store the file path of a file in the file system
35-
//const lastSlashIndex = filePath.lastIndexOf("/");
36-
// a variable is created and identified to find the last occurance of the "/" character in the filePath variable, which is used to separate directories and files in a file system
37-
//const base = filePath.slice(lastSlashIndex + 1);
38-
// a variable is created and identified to extract the base part of the filePath variable, which is the name of the file and its extension, by using the slice method
39-
//console.log(`The base part of ${filePath} is ${base}`);
40-
// console.log is used to print the base part of the filePath variable to the console, which is the name of the file and its extension
13+
const lastSlashIndex = filePath.lastIndexOf("/");
14+
const base = filePath.slice(lastSlashIndex + 1);
15+
console.log(`The base part of ${filePath} is ${base}`);
4116

4217
// Create a variable to store the dir part of the filePath variable
4318
// Create a variable to store the ext part of the variable
4419

45-
const lastSlashIndex = filePath.lastIndexOf("/");
4620
// here we have the variable lastslashIndex already created and identified its position
47-
// stores the position or (index) of "/" in filePath, so this "/" is used as a symbol that storers the number index or a place that seprate dir from base
21+
// stores the position or (index) of "/" in filePath, so this "/" is used as a symbol that storers the number index or a place that seprate dir from base
4822
const dir = filePath.slice(0, lastSlashIndex);
4923
console.log(dir);
5024
// we show our result in the console
51-
const lastDotIndex = filePath.lastIndexOf('.');
25+
const lastDotIndex = filePath.lastIndexOf(".");
5226
// we create a variable and assign its value using the indexOf to be from the dot location
5327
const ext = filePath.slice(lastDotIndex);
5428
// we create a variable where we assign its value using the slice method to be from the dot only
5529

56-
console.log(ext)
30+
// https://www.google.com/search?q=slice+mdn
31+
32+
console.log(ext);
5733
// we print our result in the console
5834
//slice(startIndex, endIndex)
5935
// means, start here and stop here. we are doing this to seprate the dir from base so we need to tell it where to start and where to end, hence that is why we use slice method,
60-
// my comments needs correcting to look profissional -_-
36+
// my comments needs correcting to look profissional -_-

0 commit comments

Comments
 (0)