Last active
November 21, 2022 04:04
-
-
Save o0pmitev/754ca03aee1fc59fb01aaa2af55a512c to your computer and use it in GitHub Desktop.
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
// (3) Convert the following array of arrays in flatten array: [1, 2, 4, 8, 6, 11, 3 , 7] | |
const toFlatten = [1, 2, [4, 8, [6, 11]], 3, 7]; | |
function flatten(arr) { | |
let newArray = []; | |
for(let i = 0; i < arr.length; i++) { | |
if(typeof(arr[i]) === 'object') { | |
newArray.push(...flatten(arr[i])); | |
} else { | |
newArray.push(arr[i]) | |
} | |
} | |
return newArray; | |
} | |
/** | |
* smooth scroll to the bottom of the page | |
*/ | |
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' }) | |
console.log(flatten(toFlatten)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment