美文网首页
三元组的js实现

三元组的js实现

作者: yorickJin | 来源:发表于2018-12-17 23:27 被阅读0次
    var triplet = {
        v: [undefined, undefined, undefined],
        initTriplet: function (v1, v2, v3) {
            this.v[0] = v1;
            this.v[1] = v2;
            this.v[2] = v3;
        },
        get: function (index) {
            return this.v[index];
        },
        put: function (index, value) {
            this.v[index] = value;
        },
        isAscending: function() {
            return this.v[0] <= this.v[1] && this.v[1] <= this.v[2];
        },
        isDescending: function() {
            return this.v[0] >= this.v[1] && this.v[1] >= this.v[2];
        },
        max: function() {
            return Math.max.apply(null, this.v);
        },
        min: function() {
            return Math.min.apply(null, this.v);
        }
    };
    

    相关文章

      网友评论

          本文标题:三元组的js实现

          本文链接:https://www.haomeiwen.com/subject/tlihkqtx.html