Skip to content

Commit 62e8714

Browse files
basic change
1 parent 54de241 commit 62e8714

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,32 @@ console.log(`The dir part of ${filePath} is ${dir}`);
2424
console.log(`The ext part of ${filePath} is ${ext}`);
2525
*/
2626

27-
function pathFinder(path){
28-
const lastSlash = path.lastIndexOf("/");
29-
const dir = path.slice(0, lastSlash);
30-
const base = path.slice(lastSlash + 1);
31-
const dot = base.lastIndexOf(".");
32-
const ext = dot !== -1 ? base.slice(dot) : "";
33-
34-
return { dir, base, ext };
27+
function pathFinder(userInput, filePath){
28+
// 1. Check if the user input exists inside the full path
29+
if (!fullPath.includes(userInput)) {
30+
console.log("Input not found in path");
31+
return;
32+
}
33+
34+
// 2. Split the path into parts
35+
const parts = filePath.split("/");
36+
37+
// 3. Base = last element
38+
const base = parts[parts.length - 1];
39+
40+
// 4. Dir = everything except the last element
41+
const dir = parts.slice(0, parts.length - 1).join("/");
42+
43+
// 5. Extension logic
44+
const dotIndex = base.lastIndexOf(".");
45+
const ext = dotIndex === -1 ? "" : base.slice(dotIndex);
46+
47+
// 6. Print everything
48+
console.log(`Full path: ${filePath}`);
49+
console.log(`Directory: ${dir}`);
50+
console.log(`Base: ${base}`);
51+
console.log(`Extension: ${ext}`);
52+
3553
}
3654

3755
console.log(pathFinder(filePath));

Sprint-1/2-mandatory-errors/1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// trying to create an age variable and then reassign the value by 1
22

33
let age = 33;
4-
age = ++age;
4+
age = age++;
55

66
console.log(age);
77

0 commit comments

Comments
 (0)