Skip to content

Instantly share code, notes, and snippets.

@tored
Created June 13, 2014 11:38
Show Gist options
  • Select an option

  • Save tored/ce5690e19f82aaa4371d to your computer and use it in GitHub Desktop.

Select an option

Save tored/ce5690e19f82aaa4371d to your computer and use it in GitHub Desktop.
extension
function extension(filename) {
return filename.split('.').pop();
}
@Ludaa

Ludaa commented Jul 7, 2014

Copy link
Copy Markdown

If filename equals "txt" then the extension popped from the array is "txt".
A solution would be to implement your function as follow :

function extension(filename) {
    return filename.split(".").slice(1).pop() || "";
}

@tored

tored commented Nov 7, 2014

Copy link
Copy Markdown
Author

Yes, good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment