West Midlands | 26-Jan-ITP | Fida H Ali Zada | Sprint 1 | coursework/sprint-1#929
West Midlands | 26-Jan-ITP | Fida H Ali Zada | Sprint 1 | coursework/sprint-1#929alizada-dev wants to merge 7 commits intoCodeYourFuture:mainfrom
Conversation
Sprint-1/1-key-exercises/3-paths.js
Outdated
| const dir = ; | ||
| const ext = ; | ||
| const dir = filePath.slice(1, lastSlashIndex); | ||
| const ext = filePath.slice(lastSlashIndex + 5); |
There was a problem hiding this comment.
Can you express the statement on line 21 so that it works for any path?
For example, "/tmp/my-project/package.json"
There was a problem hiding this comment.
Would be nice if you can show the new code here so that I don't have to locate the code in the file.
There was a problem hiding this comment.
const ext = filePath.split('/').pop().split('.').pop();
There was a problem hiding this comment.
This work but it seems a bit overdone. Can you explain how this expression work?
There was a problem hiding this comment.
Yes, sir. It is a bit overdone, but I could not find another solution because I didn't use AI.
So, this part filePath.split('/'), splits the whole file path that has slashes. And pop() takes out the last part, which in this example is package.json. Again, we split this part that has a dot. In this case, it becomes "package" "json". Finally, the last pop() will take the ext, which is json.
So, it works for all different paths.
There was a problem hiding this comment.
A more direct approach is to use filePath.lastIndexOf(). The original code has illustrated how to use it.
Why don't you use AI? It's ok to use AI, especially when you had already figured out an approach, to learn how else you could solve the problem.
|
Can you respond to each of my comment/question so that I don't have to search your code to find what you have changed? |
|
Software development is not just about writing code that works. Can you continue to respond to comments in those unresolved conversation? |
|
Yes, sir. I just got time to open my laptop. I am replying now. Thank you for pointing out those points. |
|
All comments addressed. Well done, and keep up the good work! |
Learners, PR Template
Self checklist
Changelist
I created a new branch 'coursework/sprint-1' from the main branch and completed all the coursework in the sprint-1 folder.