Skip to content

Commit df378aa

Browse files
committed
Sprint 1 exercises: complete 3-paths.js using slice and lastIndexOf
1 parent 39c0fc6 commit df378aa

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ console.log(`The base part of ${filePath} is ${base}`);
1717
// Create a variable to store the dir part of the filePath variable
1818
// Create a variable to store the ext part of the variable
1919

20-
const dir = ;
21-
const ext = ;
20+
//const dir = ;
21+
//const ext = ;
22+
23+
const dir = filePath.slice(0, lastSlashIndex);
24+
25+
const lastDotIndex = filePath.lastIndexOf(".");
26+
const ext = filePath.slice(lastDotIndex);
27+
28+
console.log(`Dir: ${dir}`);
29+
console.log(`Ext: ${ext}`);
2230

2331
// https://www.google.com/search?q=slice+mdn

Sprint-1/notes/learning-log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## What I learned
44
- Started Sprint 1 exercises and set up coursework branch
5+
- Learned how to extract directory and extension from a file path using lastIndexOf and slice.
56

67
## Errors I hit and what they mean
78
-

0 commit comments

Comments
 (0)