File tree Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change 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" ;
1113const 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
You can’t perform that action at this time.
0 commit comments