Created
March 9, 2022 14:13
-
-
Save akmalhazim/19ff4fad0d044b9e92f6f7d66d75bfe5 to your computer and use it in GitHub Desktop.
Algo playground
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
const arr = [2, [4, 3, [7, 6]]]; | |
const flatArr = []; | |
const flat = arr => { | |
if (!Array.isArray(arr)) { | |
flatArr.push(arr); | |
return | |
} | |
arr.forEach(flat); | |
} | |
flat(arr); | |
for (let i = 0; i < flatArr.length; i++) { | |
if (flatArr[i] > flatArr[i + 1]) { | |
const tmp = flatArr[i]; | |
flatArr[i] = flatArr[i + 1]; | |
flatArr[i + 1] = tmp; | |
} | |
} | |
console.log(flatArr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment