functionremoveUrlAnchor(url){if(arguments.length!==1){thrownewError("expected exactly one argument");}if(typeofurl!=="string"){thrownewTypeError("expect first argument to be a string");}if(url.length===0){return"";}const[character,...remainingUrl]=url;if(character==="#"){return"";}returncharacter+removeUrlAnchor(remainingUrl.join(""));}
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:
JavaScript
Recursive solution with runtime type checking.
Try it.
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.