flatmap (v2)

Revision 2 of this benchmark created on


Setup

const similar = Array(100).fill().map((x,i) => i%10 === 0 ? [i+1, i+100] : [i+1]);

Test runner

Ready to run.

Testing in
TestOps/sec
flatmap
similar.flatMap(
    (innerArray) => innerArray.slice(0, 1)
);
ready
flat
similar.map(innerArray => { if (innerArray.length > 1) { return innerArray.slice(0, 1); } else { return innerArray; } }).flat();
ready
set
[...new Set(similar.flat())]
ready
conditional flatmap
similar.flatMap(
    (innerArray) => innerArray.length > 1 ? innerArray.slice(0, 1) : innerArray
);
ready
map
similar.map(x => x[0]);
ready

Revisions

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