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:
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.
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.