|
Last change
on this file was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Prototype 1.1
|
-
Property mode
set to
100644
|
|
File size:
606 bytes
|
| Rev | Line | |
|---|
| [e4c61dd] | 1 | export default function(end) {
|
|---|
| 2 | var start = this,
|
|---|
| 3 | ancestor = leastCommonAncestor(start, end),
|
|---|
| 4 | nodes = [start];
|
|---|
| 5 | while (start !== ancestor) {
|
|---|
| 6 | start = start.parent;
|
|---|
| 7 | nodes.push(start);
|
|---|
| 8 | }
|
|---|
| 9 | var k = nodes.length;
|
|---|
| 10 | while (end !== ancestor) {
|
|---|
| 11 | nodes.splice(k, 0, end);
|
|---|
| 12 | end = end.parent;
|
|---|
| 13 | }
|
|---|
| 14 | return nodes;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | function leastCommonAncestor(a, b) {
|
|---|
| 18 | if (a === b) return a;
|
|---|
| 19 | var aNodes = a.ancestors(),
|
|---|
| 20 | bNodes = b.ancestors(),
|
|---|
| 21 | c = null;
|
|---|
| 22 | a = aNodes.pop();
|
|---|
| 23 | b = bNodes.pop();
|
|---|
| 24 | while (a === b) {
|
|---|
| 25 | c = a;
|
|---|
| 26 | a = aNodes.pop();
|
|---|
| 27 | b = bNodes.pop();
|
|---|
| 28 | }
|
|---|
| 29 | return c;
|
|---|
| 30 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.