Traverse DOM level by level
2022年5月1日小于 1 分钟
Traverse DOM level by level
Question
Given a DOM tree, flatten it into an one dimensional array, in the order of layer by layer, like below.
Code
/**
* @param {HTMLElement | null} root
* @return {HTMLElement[]}
*/
function flatten(root) {
// your code here
}