Test name | Executions per second |
---|---|
Array.some | 279947.7 Ops/sec |
Array.filter | 88366.6 Ops/sec |
Array.findIndex | 252965.1 Ops/sec |
var hasZero = [];
var withoutZero = [];
for (var i = 0; i < 10000; i++) {
hasZero.push(Math.floor(Math.random() * 1000));
withoutZero.push(Math.floor(Math.random() * 1000) + 1)
}
var tempResult = !!Math.round(Math.random()) ? hasZero.some(v => v === 0) : withoutZero.some(v => v === 0);
var tempResult = !!Math.round(Math.random()) ? hasZero.filter(v => v === 0) : withoutZero.filter(v => v === 0);
var tempResult = !!Math.round(Math.random()) ? hasZero.findIndex(v => v === 0) : withoutZero.findIndex(v => v === 0);