Source: https://bigfrontend.dev/problem/previous-left-sibling
// Can do recursive approach except check the previousElementSibling and lastElementChildfunction previousLeftSibling(root, target) {// If target is null, there is no previous left siblingif (!target) {return null;}// Check target's immediate previousElementSibling to see if there is a previous sibling on the same levelif (target.previousElementSibling) {return target.previousElementSibling;}let parent = target.parentElement;while (parent) {parent = previousLeftSibling(root, parent);if (parent && parent.lastElementChild) {return parent.lastElementChild;}}return null;}