Ad
  • Custom User Avatar

    This is by far the best solution I've seen. One thing that I'd like to point out, is that this method won't preserve the order of the digits going into the array. IF for some reason the order is important to you, you can use unshift() rather than push().

  • Custom User Avatar

    Beautiful! Thank you!!

  • Custom User Avatar
    // The lack of a complex test case was causing me to get a false positive
    // using an incorrect solution. I think a test similar to this one should be added.
    it("should test some large amount of digits", function(){
      Test.assertEquals(solution("214554333233311222499998234567894"), 99998, "Large amount of digits");
    });
    
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    As a general best practice when extending base objects, you should protect against the existence of your new function.. For example do something like:

    Number.prototype.digits = Number.prototype.digits || function() {...}
    

    Also, it would be nice to have some comments in your digits() method that explains what it is doing. Other than that your code looks really good and reads well.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution