ptitlutins/app/utils/siblingsOf.ts
2026-06-10 23:37:21 +02:00

10 lines
397 B
TypeScript

import type { Node } from "~/types"
import { resolvePath } from "./resolvePath"
import { childrenOf } from "./childrenOf"
/** Siblings (display order) of the node at `path` ([root] at depth 0). */
export const siblingsOf = (root: Node, path: string[]): Node[] => {
const chain = resolvePath(root, path)
if (chain.length < 2) return [chain[0]!]
return childrenOf(chain[chain.length - 2]!)
}