Skip to content

Instantly share code, notes, and snippets.

@iRealNirmal
iRealNirmal / deflat array
Created May 23, 2016 10:34
Function that flattens an array of arbitrarily nested arrays of integers into a flat array of integers
function flattenArrayOfArrays(a, r){
if(!r){ r = []}
for(var i=0; i<a.length; i++){
if(a[i].constructor == Array){
console.log(r)
flattenArrayOfArrays(a[i], r);
}else{
r.push(a[i]);
}
}