I am developing a large javascript application and unsurprisingly in IE11 it really struggles (Chrome = 8 secs, nodejs= 8 secs, IE11 = 35 secs).
So I did some profiling and found that this method is my time sink. I have already made all the changes I could think of - is there any other performance improvement modification I can put in place?
const flatten = function(arr, result) {
if (!Array.isArray(arr)) {
return [arr];
}
if(!result){
result = [];
}
for (let i = 0, length = arr.length; i < length; i++) {
const value = arr[i];
if (Array.isArray(value)) {
flatten(value, result);
}
else {
result.push(value);
}
}
return result;
};
The method gets called lots of times, with smallish arrays (up to 10 string items, no more than 2 level deep).