Skip to content

Comment on You Can't JavaScript Under Pressure

Comments

there's a truly dubious test case in the File Extension test.

file called .htaccess is not filename "" and extension "htaccess" with a "." separating the two. .htaccess is a unix style dotfile. its whole name is ".htaccess" and it has no file extension.

I have to admit to cheating and putting 'if (i === '.htaccess') return 'htaccess';' to save time :)

I just did

return i.indexOf('.') > -1 ? i.substring(i.indexOf('.')+1) : false;

Seemed to pass all test cases

Aye, I did similarly, though for some reason I did >= 0 instead of > -1. I wonder what % of people choose one test approach vs. the other?

I chose >= 0, it's fun to learn!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.