Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6227769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:16:41+00:00 2026-05-24T09:16:41+00:00

My code so far: // The q constant of the Glicko system. var q

  • 0

My code so far:

// The q constant of the Glicko system.
var q = Math.log(10) / 400;

function Player(rating, rd) {
    this.rating = rating || 1500;
    this.rd = rd || 200;
}

Player.prototype.preRatingRD = function(this, t, c) {
    // Set default values of t and c
    this.t = t || 1;
    this.c = c || 63.2;
    // Calculate the new rating deviation
    this.rd = Math.sqrt(Math.pow(this.rd, 2) + (Math.pow(c, 2) * t));
    // Ensure RD doesn't rise above that of an unrated player
    this.rd = Math.min(this.rd, 350);
    // Ensure RD doesn't drop too low so that rating can still change
    // appreciably
    this.rd = Math.max(this.rd, 30);
};
Player.prototype.g = function(this, rd) {
    return 1 / Math.sqrt(1 + 3 * Math.pow(q, 2) * Math.pow(rd, 2) / Math.pow(Math.PI, 2));
};
Player.prototype.e = function(this, p2rating, p2rd) {
    return 1 / (1 + Math.pow(10, (-1 * this.g(p2rd) * (this.rating - p2rating) / 400)));
};

I’m working on a JS/HTML implementation of the Glicko rating system and am heavily borrowing from pyglicko — which is to say, completely ripping it off.

It’s rather short (probably less than 100 LoC without comments) but I’m having my misgivings about whether my translation will work because honestly, I have no idea how Javascript scoping and this actually work. You can see what I have at the link at the top.

But in specific I’m wondering how you would express this bit of Python code in Javascript. Basically _d2 is inside a class definition for Player.

def _d2(self, rating_list, RD_list):
    tempSum = 0
    for i in range(len(rating_list)):
        tempE = self._E(rating_list[i], RD_list[i])
        tempSum += math.pow(self._g(RD_list[1]), 2) * tempE * (1 - tempE)
    return 1 / (math.pow(self._q, 2) * tempSum)

I’ve got the functions e and g defined like so, and q is a constant:

Player.prototype.e = function(this, ratingList, rdList) {
    // Stuff goes here
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:16:42+00:00Added an answer on May 24, 2026 at 9:16 am

    In Javascript you don’t need o pass the self explicitly (Python is the “weird” one here, actually)

    Player.prototype.e = function(rating_list, RD_list){
        //replace "self" with "this" here:
        var tempSum = 0; //if you don't use the "var", tempSum will be a global
                         // instead of a local
        for(var i=0; i<rating_list.length; i++){ //plain old for loop - no foreach in JS
            var tempE = this._E( ... ); //note that in JS, just like in Python,
                                        //variables like this have function scope and
                                        //can be accessed outside the loop as well
            tempSum += Math.pow( ... ) //the Math namespace is always available
                                       //Javascript doesn't have a native module system
        }
        return (...);
    }
    

    This should work all right.
    The only tricky thing you need to know about this is that it is very promiscuous. This means that is is determined by how you call the function:

     obj.e(); //if you do a method-like call, the this will be set to obj
    

    However, there is no magic binding behind the scenes. The following works in python but does not work in Javascript:

     f = obj.e
     f(); //looks like a normal function call. This doesn't point to obj
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SO this is my code so far: JS: <script type=text/javascript> function Hide(srcField) { var
This is my code so far: var n = 123456789; var d = n.toString().length;
I have this code so far which perfectly but relies on there being a
Hey im having this code so far - (id)initWithDictionary:(NSDictionary *)aDictionary { self = [super
This is what I have as far as code, it is in the first
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
Ok. here's the operations i successfully code so far thank's to your help: Adittion:
I've been cleaning up my code and so far so good, and I only
How far is the code for best functionallity? I have two ComboBox, so the
So far i have got the code below which works lovely when trying an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.