Skip to content

Instantly share code, notes, and snippets.

@tored
Created June 13, 2014 11:38
Show Gist options
  • Save tored/ce5690e19f82aaa4371d to your computer and use it in GitHub Desktop.
Save tored/ce5690e19f82aaa4371d to your computer and use it in GitHub Desktop.
extension
function extension(filename) {
return filename.split('.').pop();
}
@Ludaa
Copy link

Ludaa commented Jul 7, 2014

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
Copy link
Author

tored commented Nov 7, 2014

Yes, good catch.

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