var ArrayUtil = {
    binarySearch: function(a, i, c, f) {
        var s = 0
          , e = a.length - 1;
        while (e - s > 1) {
            var m = Math.floor((e + s) / 2);
            var r = c(i, a[m]);
            if (r < 0)
                e = m;
            else if (r > 0)
                s = m;
            else
                return m;
        }
        if (!f)
            return -e;
        else {
            var rs = Math.abs(c(i, a[s]));
            var re = Math.abs(c(i, a[e]));
            if (re < rs)
                return e;
            else
                return s;
        }
    }
};
