1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var cache = {};
var family = {};

function add(parent, child){
    var p,c;
    if(parent in cache){
        p = cache[parent];
    } else { //初めての名前
        p = family[parent] = { name : parent };
        cache[parent] = p;
    }
    if(child in cache){
        p[child] = cache[child];
    } else { //初めての名前
        c = p[child] = { name : child };
        cache[child] = c;
    }
}

family_toString.tab = "  ";

function family_toString(f, tab){
    var result = "";

    if(tab == null) tab = -1;

    var indent = arguments.callee.tab.x(tab);

    for( x in f){
        if(x == "name") continue;
        else{
            result += indent + (tab < 0 ? "" : "->") + f[x].name + "\n";
            result += family_toString(f[x], tab+1);
        }
    }
    return result;
}

if(!String.prototype.x){
    String.prototype.x = function(n){
        var result="", i;
        for(i=0;i<n;i++){
            result += this;
        }
        return result;
    }
}