Test name | Executions per second |
---|---|
Array.some | 331672.8 Ops/sec |
Array.filter | 66685.4 Ops/sec |
Array.findIndex | 351110.2 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);