Test name | Executions per second |
---|---|
RegExp replace | 4387254.0 Ops/sec |
String ops | 6827613.0 Ops/sec |
const strip = (str) => str.replace(/\/?index$/, '');
strip('en/index');
strip('index');
strip('en/guides/getting-started');
const strip = (str) => str === 'index' ? '' : str.endsWith('/index') ? str.slice(0, -6) : str;
strip('en/index');
strip('index');
strip('en/guides/getting-started');