Created
January 21, 2020 10:22
-
-
Save erperejildo/643515971a931c05f81173ab017e8a97 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
// First try I was detecting if it was an array or not and create some loops | |
// if so, but I thought on an easier way to avoid some recursivity | |
const fixArray = function(array) { | |
const arrayString = array.toLocaleString(); // "1,2,3..." | |
const fixedArray = arrayString.split(',').map(function(item) { | |
return parseInt(item, 10); | |
}); | |
console.log(fixedArray); | |
return fixedArray; | |
} | |
const nestedArrays1 = [[1,2,[3]],4]; | |
const nestedArrays2 = [[1,2,[3]],4,[[[5]]]]; | |
const nestedArrays3 = [1,2,[3,4,5]]; | |
const fixedArray1 = fixArray(nestedArrays1); | |
const fixedArray2 = fixArray(nestedArrays2); | |
const fixedArray3 = fixArray(nestedArrays3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment