I just did several modifications to the algorithm to find the fastest solution in JavaScript using JSPerf. Turns out, the fastest way to get this done is by doing this:
function removeUrlAnchor(url) { const index = url.indexOf("#"); return index === -1 ? url : url.slice(0, index); }
I also removed the runtime type checking for the tests.
Tests are available here (tested in Chromium only).
How fast is my implementation?
Hi Josh. You could use JSPerf to test your code. It is really simple to get up and running your own benchmarks.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I just did several modifications to the algorithm to find the fastest solution in JavaScript using JSPerf. Turns out, the fastest way to get this done is by doing this:
I also removed the runtime type checking for the tests.
Tests are available here (tested in Chromium only).
How fast is my implementation?
Hi Josh. You could use JSPerf to test your code. It is really simple to get up and running your own benchmarks.