Test name | Executions per second |
---|---|
Map and Filter | 462.7 Ops/sec |
for loop | 2130.8 Ops/sec |
var data = Array.from({length: 100000}, (_, i) => i);
const results = data
.map((value) => value * 2)
.filter((value) => value % 4 === 0);
return results;
const length = data.length;
const results = [];
for (let j = 0; j < length; j++) {
const value = data[j];
if (value % 2 === 0 && value % 4 === 0) {
results.push(value * 2);
}
}
return results;