indexOf dans filter

Benchmark created on


Setup

const someArray = new Array(1000).map(() => Math.random())
const someElement = -1

const supprimeElement = (tableau, elementASupprimer) => [
  ...tableau.filter((_, i) => i < tableau.indexOf(elementASupprimer)),
  ...tableau.filter((_, i) => i > tableau.indexOf(elementASupprimer)),
];
const supprimeElementOpt = (tableau, elementASupprimer) => {
  const indexOccurence = tableau.indexOf(elementASupprimer);
  return tableau.filter((_, i) => i !== indexOccurence);
};

Test runner

Ready to run.

Testing in
TestOps/sec
supprimeElement
supprimeElement(someArray, someElement)
ready
supprimeElementOpt
supprimeElementOpt(someArray, someElement)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.