← Back to challenges

Get the File Name

JavaScriptHardregexlanguage_fundamentalsarrays

Instructions

Create a function that returns the selected filename from a path. Include the extension in your answer.

Examples

getFilename("C:/Projects/pil_tests/ascii/innokodakademija.txt") ➞ "innokodakademija.txt"

getFilename("C:/Users/johnsmith/Music/Beethoven_5.mp3") ➞ "Beethoven_5.mp3"

getFilename("ffprobe.exe") ➞ "ffprobe.exe"

Notes

  • Tests will include both absolute and relative paths.
  • For simplicity, all paths will include forward slashes.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: ES6: Destructuring Arrays II