Created
September 27, 2023 06:41
-
-
Save intrnl/a9b51b4a495dc77df383f6ecfa890e9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 FOLLOWING = 4; | |
const CONTAINED_BY = 16; | |
const PRECEDING = 2; | |
const CONTAINS = 8; | |
export const collateNode = (a: Node, b: Node) => { | |
const position = a.compareDocumentPosition(b); | |
if (position & (FOLLOWING | CONTAINED_BY)) { | |
return -1; | |
} | |
if (position & (PRECEDING | CONTAINS)) { | |
return 1; | |
} | |
return 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment