Test name | Executions per second |
---|---|
Custom Flatten Function | 849704.4 Ops/sec |
Array.prototype.flat | 1040658.2 Ops/sec |
function flatten(arr) {
let i = 0;
const len = arr.length;
const result = [];
let item;
while (i < len) {
item = Array.isArray(arr[i]) ? flatten(arr[i]) : [arr[i]];
[].push.apply(result, item);
i += 1;
}
return result;
}
var params = [ "hello", true, 7 ];
var other = flatten([1, 2, params]);
var params = [ "hello", true, 7 ];
var other = [1, 2, params].flat()