const array = [];
for (let i = 0; i < 10000; i++) {
array.push(i);
}
let result = 0; // accumulate benchmark results so that optimizer cannot throw out any part of our code
const res = _(array).filter(n => n % 2).map(n => Math.sqrt(n)).take(5).value();
result += res[0];
const res = array.filter(n => n % 2).map(n => Math.sqrt(n)).slice(0, 5);
result += res[0];
const res = [];
for (let i = 0; i < array.length; i++) {
const n = array[i];
if (n % 2) { // filter(n => n % 2)
const n2 = Math.sqrt(n); // map(n => Math.sqrt(n))
res.push(n2);
if (res.length >= 5) break; // take(5)
}
}
result += res[0];