7 kyu

Sign in/Sign out but sign it

967 of 970ZozoFouchtra
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • danik00111 Avatar

    i wanted to make this kata, but it was a dupe of this :p

  • FArekkusu Avatar

    No random tests.

    • JohanWiltink Avatar

      As of now, random tests have random inputs, but not random expected values. That means they're predictable, can be hardcoded, and are insufficient as random tests.

      That said, hardcoding this kata hardly seems worth it; it's less work to just solve it.

  • Javatlacati Avatar

    CoffeeScript translation kumited! Please Accept :D

  • brice Avatar

    Just formal issue : Add a message in comment. Great Kata.

  • OverZealous Avatar

    This comment has been hidden.

  • SteveRuble Avatar

    This comment has been hidden.

    • ZozoFouchtra Avatar

      This comment has been hidden.

    • computerguy103 Avatar

      Believe it or not, there is a relatively simple explanation, and it isn't that Javascript treats them differently. It's because of Array.prototype.toString, and how that string is subsequently coerced to a number.

      When necessary to perform comparisons between an object and a primitive, the object is coerced to a string using its toString method:

      [1,2] > 0 becomes "1,2" > 0

      Now, if one side of a comparison is a number (or boolean), the other side is coerced to a number as well; otherwise, they're compared as strings. So:

      "1,2" > 0 becomes NaN > 0

      "1,2" > "0" isn't changed, because neither side is a number

      If you change Array.prototype.toString, then an array such as [1,2] can become any string you want it to become. E.g.

      // default behavior: join on ','
      [1,2] == "1,2";           // true: "1,2" == "1,2" is true
      [1,2] == NaN;             // false: NaN == NaN is false
      [1,2] > 0;                // false: NaN > 0 is false
      
      // new behavior: join on '.'
      Array.prototype.toString = function () { return this.join('.'); };
      [1,2] == "1.2";           // true: "1.2" == "1.2" is true
      [1,2] == 1.2;             // true: 1.2 == 1.2 is true
      [1,2] > 0;                // true: 1.2 > 0 is true
      
      // new behavior: join on 'e' (coercing "1e2" to a number yields 100)
      Array.prototype.toString = function () { return this.join('e'); };
      [1,2] == "1e2";           // true: "1e2" == "1e2" is true
      [1,2] == 100;             // true: 100 == 100 is true
      [1,2] > 0;                // true: 100 > 0 is true
      
      // new behavior: join on 'x' (coercing "0x10" to a number yields 16)
      Array.prototype.toString = function () { return this.join('x'); };
      [0,10] == "0x10";         // true: "0x10" == "0x10" is true
      [0,10] == 16;             // true: 16 == 16 is true
      [0,10] > 0;               // true: 16 > 0 is true
      
      // new behavior: join on ''
      Array.prototype.toString = function () { return this.join(''); };
      [1,2,3,4,5] == "12345";   // true: "12345" == "12345" is true
      [1,2,3,4,5] == 12345;     // true: 12345 == 12345 is true
      [1,2,3,4,5] > 0;          // true: 12345 > 0 is true
      
  • wthit56 Avatar

    Simple and straightforward. Good job.