File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change 1010// (All spaces in the "" line should be ignored. They are purely for formatting.)
1111
1212const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt" ;
13+
1314const lastSlashIndex = filePath . lastIndexOf ( "/" ) ;
1415const 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- const dir = ;
21- const ext = ;
16+ // +1 to not include the slash in the base
17+ // lastSlashIndex finds position of the last / in the string
18+ // slice extracts part of the string from that position to the end
19+ const dir = filePath . slice ( 0 , lastSlashIndex ) ;
2220
23- // https://www.google.com/search?q=slice+mdn
21+ const dotIndex = base . lastIndexOf ( "." ) ;
22+ const ext = base . slice ( dotIndex ) ;
23+ // dotIndex finds position of the last . in the base string and slice extracts after this
24+ console . log ( `The base part of the file path is ${ base } , the dir part is ${ dir } , and the ext part is ${ ext } ` ) ;
You can’t perform that action at this time.
0 commit comments