//************** JQuery extension **************//

(function ($) {
    var jqAppend = $.fn.append;
    $.fn.append = function () {
        // Make a list of arguments that are jQuery objects
        var appendages = $.makeArray(arguments).filter(function (arg) {
            return arg instanceof $;
        });

        // Call the actual function
        var returnValue = jqAppend.apply(this, arguments);

        // Trigger "append" event on all jQuery objects that were appended
        for (var i = 0; i < appendages.length; ++i) {
            appendages[i].trigger('append');
        }

        return returnValue;
    };
})(jQuery)

//************** Array extension **************//

Array.prototype.sum = function () {
    var r = 0;
    for (var i = 0; i < this.length; i++) {
        r += this[i];
    }
    return r;
};

Array.prototype.avg = function () {
    var r = 0;
    for (var i = 0; i < this.length; i++) {
        r += this[i];
    }
    return r / this.length;
};