Hacker News new | ask | show | jobs
by kittenfluff 4004 days ago
Responds "Yes" to

  9007199254740990, 9007199254740991, 9007199254740992
but "No" to

  9007199254740991, 9007199254740992, 9007199254740993
Presumably this is due to how Javascript handles integers, i.e. it uses the integer part of a float64, to wit

  > parseInt('9007199254740992')
  9007199254740992
  > parseInt('9007199254740993')
  9007199254740992
Edit: I think this is the code that actually reads the numbers the user enters, see [0]

  function l(){
      var a=h.exec(m[1]),f=null,g=null,n=null;
      return a&&(null!==a[1]&&a[1]&&(f=parseInt(a[1],10)),
          null!==a[2]&&a[2]&&(g=parseInt(a[2],10)),
          null!==a[3]&&a[3]&&(n=parseInt(a[3],10))),
      new e(f,g,n)
  }
Edit(2): Actually, I'm not so sure that's the correct code at all. They NYT game is capable of parsing floats correctly (e.g. it accepts 1.1, 1.2, 1.3 as a "Yes") so it's not just using parseInt.

[0] http://a1.nyt.com/assets/interactive/20150612-151638/js/foun...

3 comments

The actual code seems to be from here [0]

on line 588 is the comparison

    var rightWrong = (inputData[0] < inputData[1]) & (inputData[1] < inputData[2]) ? right : wrong;
With a variable declaration on line 545 being

    var inputData = [NaN, NaN, NaN],
        revealed = false,
        right = "<p class = 'g-answer g-yes'>Yes!</p>",
        wrong = "<p class = 'g-answer g-no'>No.</p>";
And `inputData` is changed on text input on line 662

    $("#g-input input").each(function(i) {
        var val = $(this).val();
        inputData[i] = $.isNumeric(val) ? Number(val) : NaN;
    });
It uses the `Number()` function to convert from the input text to an actual number, so it can convert any number format defined by ES5[1] or ES6[2]. So in ES6 you can use binary (0b, 0B) and octal (0o, 0O) formatting along with exponential (1e-2) and hex (0x, 0X). Binary and octal works for me currently on Chrome 43 OS X.

[0] http://graphics8.nytimes.com/newsgraphics/2015/06/16/puzzle/...

[1] http://www.ecma-international.org/ecma-262/5.1/#sec-9.3.1

[2] http://www.ecma-international.org/ecma-262/6.0/#sec-7.1.3.1

yeah alright.. i think someone didn't actually get the point of the article hehe
you broke it.