File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed
Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change 1212const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt" ;
1313const lastSlashIndex = filePath . lastIndexOf ( "/" ) ;
1414const 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;
2120filePath . slice ( 0 , lastSlashIndex ) ;
22- const ext = filePath ;
2321filePath
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 } ` ) ;
You can’t perform that action at this time.
0 commit comments