You need to sign in or sign up before continuing.×
Ad
  • Custom User Avatar

    The test cases are not specifically enough, I wonder if you can add the following cases:

    // for negative integers
    Test.expect(((-2).twos(4) == "1110"),"-2 in 4 bits == 1110");
    
    // for results over 32bits
    Test.expect(((-10).twos(32) == "11111111111111111111111111110110"),"-10 in 32 bits == 11111111111111111111111111110110");
    
  • Custom User Avatar

    This doesn't work! (-2).twos(4) returns '1010' which should be '1110'

  • Custom User Avatar

    This is awesome but will go wrong while I wanna get a string of length >= 32. In JavaScript, numbers are storaged with 64bits but presented with 32bits, so 1 << 32(or higher) is '0...000' not '1...000', which causes the error.

  • Custom User Avatar

    I suggest adding test case for variable length arguments like this :

    function add() {
        return [].slice.call(arguments).reduce(function(p, c) {
            return p + c;
        }, 0);
    }
    
    var add_ = defaultArguments(add);
    Test.assertEquals(add_(1,2,3), 6);
    
    add_ = defaultArguments(add_);
    Test.assertEquals(add_(2,3), 5);