Created
July 21, 2013 19:13
-
-
Save kurisuwhyte/6049603 to your computer and use it in GitHub Desktop.
Higher-order functions for computing the sibling of an element
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
function findElement(node, stepper) { | |
var x | |
return isRoot(node)? stepper(node) | |
: x = stepper(node)? x | |
: /* otherwise */ findElement(node.parentNode, stepper) | |
} | |
function findNextSibling(node) { | |
return findElement(node, function(el) { return el.nextSibling }) | |
} | |
function findPrevSibling(node) { | |
return findElement(node, function(el) { return el.previousSibling }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment