Nodejs Number Compare compare_number(generated_number, input_number)

Here you can find the source of compare_number(generated_number, input_number)

Method Source Code

Number.prototype.compare_number = function (generated_number, input_number) {
    var number_of_A = 0;
    var number_of_B = 0;

    for (var i=0; i<4; i++){
        for (var j=0; j<4; j++){
            if ((generated_number[i] == input_number[j]) && i==j){
                number_of_A += 1;//  w  w w . j  a  va  2 s.c  om
            }
            else if ((generated_number[i] == input_number[j]) && i!=j){
                number_of_B += 1;
            }
        }
    }

    return number_of_A+'A'+number_of_B+'B';
};

Related

  1. compareTo(num)
    Number.prototype.compareTo = function(num) {
       if (typeof num != "number") return false; 
       if (num < this) return 1;
       else if (num > this) return -1;
       else return 0;
    };
    
  2. compareTo(other)
    Number.prototype.compareTo = function (other) {
        return this.valueOf() == other;
    };
    
  3. compareTo(other: number)
    Number.prototype.compareTo = function (other: number) {
       return this.valueOf() == other;