Last active
September 9, 2018 13:12
-
-
Save mota57/14556820509d3d2fbeefce8b6d2db18e to your computer and use it in GitHub Desktop.
Simple Flat Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FlatArray = (function(){ | |
var vm = this; | |
vm.row = []; | |
function CallFlatFunction(inputs) | |
{ | |
var result = FlatFunction(inputs); | |
vm.row = []; | |
return result; | |
} | |
function FlatFunction(inputs){ | |
for(var i in inputs) | |
{ | |
var el = inputs[i] | |
if(isArray(el)){ | |
FlatFunction(el); | |
} else{ | |
vm.row.push(el); | |
} | |
} | |
return vm.row; | |
} | |
function isArray(element) | |
{ | |
return Object.getPrototypeOf(element).constructor === Array ? true: false; | |
} | |
return { | |
Flat: CallFlatFunction, | |
} | |
})(); | |
var test_a = [[1,2,[3, [40]]],4]; | |
console.log(FlatArray.Flat(test_a)); //[ 1, 2, 3, 40, 4 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment