DEV Community

loading...

Discussion on: Daily Challenge #131 - Remove Anchor from URL

Collapse
aminnairi profile image
Amin

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

benchmark

Collapse
thepeoplesbourgeois profile image
Thread Thread
aminnairi profile image
Amin

Hi Josh. You could use JSPerf to test your code. It is really simple to get up and running your own benchmarks.