Last active
July 21, 2016 08:51
-
-
Save vinaybedre/429befea2f15f4e8cd951434324122dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //ArrayFlatter, flatens array of any nested levels | |
| var arrayFlatter = function(){ | |
| /** | |
| * Method to flatten input array. | |
| * @param {string} input - Input array, containing deeply nested array | |
| */ | |
| this.flatArray = function(input){ | |
| return new Array(JSON.stringify(input).replace(/[\[\]]/g,"")); | |
| } | |
| } | |
| var input = [[1,2,[3]],4]; | |
| var arrayFlat = new arrayFlatter(); | |
| var output = arrayFlat.flatArray(input); | |
| console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment