/**
* Returns an array that contains non-array elements.
* If an element is an array, then the element is replaced by the content of the array.
* @param{Array}
* @return{Array} return null if no arguments are passed.
* @example
flatten([[1,2],3,[4]]); // returns [1,2,3,4];
*/
var flatten = function(arr){
if(!Array.isArray(arr)){
return (arr === null || arr === undefined) ? null : [arr];
}
var result = [], obj;
for(var i = 0, len = arr.length; i < len; i++){
obj = arr[i];
if(Array.isArray(arr)){
obj = flatten(obj);
}
result = result.concat( obj );
}
return result;
};
What REALLY is Data Science? Told by a Data Scientist - By Joma Tech
Writing perfect code is a challenging process. That's where code reviews come in to help…
"The Next Leap: How A.I. will change the 3D industry - Andrew Price - Blender"
"Captain Disillusion: World's Greatest Blenderer - Live at the Blender Conference 2018 - CaptainDisillusion"
My 5 Favorite Linux Shell Tricks for SPEEEEEED (and efficiency) - By tutoriaLinux > What's…