summaryrefslogtreecommitdiff
path: root/javascript/test-sort.js
blob: 5d6c6ef68497f31a3f07600cbfeb516db2225efe (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const fs = require('fs');

var keys = [
    {
        w: 'ok',
        f: 200,
        c: [
            { w: 'one', f: 100 },
            { w: 'two', f: 200 },
            { w: 'three', f: 300 },
            { w: 'four', f: 400 }
        ]
    },
    {
        w: 'nope',
        f: 150,
        c: [
            { w: 'one', f: 1000 },
            { w: 'two', f: 200 },
            { w: 'three', f: 30 },
            { w: 'four', f: 4 }
        ]
    },
    {
        w: 'maybe',
        f: 300,
        c: [
            { w: 'one', f: 3 },
            { w: 'two', f: 3 },
            { w: 'three', f: 5 },
            { w: 'four', f: 4 }
        ]
    }
];

keys.forEach( it => {
    it.c = it.c.sort((a, b) => b.f - a.f );
});
keys = keys.sort((a, b) => b.f - a.f );

console.log(JSON.stringify(keys, undefined, 2));


let rawdata = fs.readFileSync('results/keywords.json');
let _keywords = JSON.parse(rawdata);

function get_root(x) {
    var response;
    _keywords.forEach( o => { if ( o.w[0] == x[0] ) response = o; })
    return response;
}

function find_root(x) {
    return _keywords.find( o => o.w[0] == x[0]);
}

function for_root(x) {
    for(j=0; j<_keywords.length; j++)
        if (_keywords[j].w[0] == x[0]) return _keywords[j];
    return false;
}
// _keywords.forEach( it => {
//     obj = get_root(it.w);
// })

o1 = get_root(['Επιφάνειες']);
o2 = find_root(['Επιφάνειες']);
o3 = for_root(['Επιφάνειες']);

console.log(JSON.stringify(o1));
console.log(JSON.stringify(o2));
console.log(JSON.stringify(o3));
// for(i=0; i<100000; i++) o1 = get_root(['Επιφάνειες']);
// for(i=0; i<1000000; i++) o1 = find_root(['Επιφάνειες']);
for(i=0; i<1000000; i++) o1 = for_root(['Επιφάνειες']);