JSFiddle - React, Tailwind, and code Playground

by Steven Senkus

JavaScript

var stats = {
    searchTrackable: false,
    pageSize: 50, // this should be passed in as a parameter somewhere...
    totalExactMatches: 0,
    totalSimilarMatches: 0,
    initMatchesLoaded: false,
    exactPageCount: 0,
    similarPageCount: 0,
    totalPageCount: 0,

    addExact: function (numMatches) {
        this.totalExactMatches += numMatches;
        this.exactPageCount = this.roundPageCount(this.totalExactMatches);
    },
    addSimilar: function (numMatches) {
        this.totalSimilarMatches += numMatches;
        this.similarPageCount = this.roundPageCount(this.totalSimilarMatches);
    },
    roundPageCount: function (val) {
        return Math.ceil(val / this.pageSize);
    },
    getTotalPageCount: function () {
        this.totalPageCount = this.exactPageCount + this.similarPageCount;
        return this.totalPageCount;
    },
    getLabel: function () {
        var label = this.getTotalPageCount() + ' T,' + this.exactPageCount + ' E,' + this.similarPageCount + ' S';
        return label;
    }
};


console.log(stats);
console.log(stats.getLabel());
console.log(stats.addExact(1090))
console.log(stats.getLabel());