# Even Odd (Array || TypedArray) split

## Description

Outputting two new Arrays or TypedArrays that are even and odd split of an input Array.

## Setup

``````const size = 2**12
let input = new Float32Array(size, () => Math.random())
``````

## Test runner

Testing in
TestOps/sec
Filter
``````() => {
return [
input.filter((_, i) => i & 1),
input.filter((_, i) => !(i & 1))
]
}``````
for loop
``````() => {
const l = input.length
const l2 = Math.ceil(l / 2)
const a = new input.constructor(l2)
const b = new input.constructor(l2)
let j = 0, k = 0
for(let i = 0; i < l; i++) {
if(i & 1) b[j++] = input[i]
else a[k++] = input[i]
}
return [a, b]
}``````
Reduce
``````() => {
const l = input.length;
const l2 = Math.ceil(l / 2);
const [a, b] = input.reduce(
([even, odd], value, index) => {
if (index & 1) odd[index >> 1] = value;
else even[index >> 1] = value;
return [even, odd];
},
[new input.constructor(l2), new input.constructor(l2)]
);
return [a, b];
}
``````
Separate for loops
``````() => {
const l = input.length;
const l2 = Math.ceil(l / 2);
const a = new input.constructor(l2);
const b = new input.constructor(l2);
let j = 0;
for (let i = 0; i < l; i += 2) {
a[j++] = input[i];
}
j = 0;
for (let i = 1; i < l; i += 2) {
b[j++] = input[i];
}
return [a, b];
}``````
``````() => {