Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/utils/lib/hash.js
blob: 7caa086a353fcb2c738b6ad2d727f63706974d97 (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
// Hash object

var Hash = exports.Hash = {};

Hash.merge = function(hash, other) {
    var merged = {};
    if (hash) Hash.update(merged, hash);
    if (other) Hash.update(merged, other);
    return merged;
}

Hash.update = function(hash, other) {
    for (var key in other)
        hash[key] = other[key];
    return hash;
}

Hash.forEach = function(hash, block) {
    for (var key in hash)
        block(key, hash[key]);
}

Hash.map = function(hash, block) {
    var result = [];
    for (var key in hash)
        result.push(block(key, hash[key]));
    return result;
}