6 kyu

intToBits(int, length)

Description
Loading description...
Bits
Fundamentals
  • Please sign in or sign up to leave a comment.
  • elyasafe Avatar

    absurd test cases, lack of definitions for valid arguments.

  • akar-0 Avatar

    Nice kata, except, IMO, the need to check for absurd values passed to length (NaN or such...).

  • joebien Avatar

    It would be helpful to see some sample inputs with expected outputs. My code seems to fullfill the task but I get Test didn't pass: Unknown error.

    HELP!

  • computerguy103 Avatar

    This comment has been hidden.

  • computerguy103 Avatar

    This comment has been hidden.

  • computerguy103 Avatar

    This comment has been hidden.

  • Not4Now Avatar

    it dosen't check the length correctly

  • SagePtr Avatar

    And it's still unknown to me, what should return for example intToBits(-5, 2) ? How much bits it should capture from '1...11111011' ?

  • OverZealous Avatar

    It's a little confusing at the end of your description, because you state:

    ints have 32 bits in total, so the string you return should have 32 characters, each a 1 or a 0.

    However, with the optional length argument, this isn't true. You can have an arbitrary number of characters.


    In the description, you state that 0 or greater is valid for the optional length parameter. Should that be 1 or greater? Or should the function allow the integer 0 to return an empty string ''?

    On a related note, you don't have any tests for validity of length, maybe you should make it clear that the function doesn't have to check for a valid length parameter.

    Also, your setup function doesn't declare the length parameter, making it potentially confusing. Since dealing with optional parameters isn't really a critical part of this kata, I recommend changing your setup code to be:

    function intToBits(int, length) {
      length = length || 32;
      
      // Add your code here
      
    }
    

    This makes it clear that length is optional (that's standard JS format for optional params), as well as making it clear you don't have to worry about testing it for validity.


    (On a side note: did you know that while int was a future-reserved keyword in ECMAScript 2 and 3, it is no longer reserved in ECMAScript 5? I didn't! It looks like they removed most of the future reserved keywords in ES5.

  • joeycozza Avatar

    I felt this was a great kata. Description was clear and concise, and I liked the technical aspect of it.

  • jacobb Avatar

    You also should be explicitly testing for -1 and 0.

  • jacobb Avatar

    You should specify that you're expecting a 32-bit width and a two's complement representation in the description even though it's easy enough to figure out with the test cases for people familiar with binary representations. However, it would be nice for the people who have no idea to give them that bit of info.