Test name | Executions per second |
---|---|
RegExp replace | 4351416.0 Ops/sec |
String ops | 11359012.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');