1var partition = function (head, x) {2if (!head) {3return head;4}5const less = [];6const greater = [];7let concat;8rec(head);9return head;1011function rec(currentNode) {12if (currentNode.val < x) {13less.push(currentNode.val);14} else {15greater.push(currentNode.val);16}17if (!currentNode.next) {18concat = [...less, ...greater];19currentNode.val = concat.pop();20return;21}22rec(currentNode.next);23currentNode.val = concat.pop();24}25};