Ad
  • Custom User Avatar

    I don't remember if the JS translatiion is from Jack or from Giacomo and I can't edit it anymore!

  • Default User Avatar

    Awesome help, the sort integer thing is something I've seen on here in other people's code but not understood until your reference. Thanks once again for the great advice :)

  • Default User Avatar

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

  • Custom User Avatar

    The false is not the problem.
    When you return false, you are giving the correct answer instead of the other wrong stuff.
    When you give a correct answer, you move on to the next batch of tests which is where your code fails.

    The major bug in the code is here

    for (i=0; i<array1.length; i++)
    

    Always use var i. As of now, you are modifying the global variable i.
    I actually can't believe that the test code is making the same mistake and using a global i instead of a var i.

    As a result, your function and the test code are messing with each other. I am not really sure how exactly the submission timeout error is occuring, but this mutual interaction is definitely the cause.

    Also, the sort function by default uses string sort, even if the arguments are numbers.
    So, [9, 100, 20, 25] will get sorted as [100, 20, 25, 9] instead of [9, 20, 25, 100].

    Sometimes this difference in sorting won't matter. Sometimes it will.

    How to sort an array of integers correctly

  • Custom User Avatar

    The problem in the code is not the type of numbers.
    The problem is that you are making a fixed size array at the start.

    Here is what happens when i = 2, j = 0 i.e. the third iteration of the main loop.
    arrayTable[i] is arrayTable[2] but arrayTable has just 2 elements, so arrayTable[i] is undefined.

    Now, if you were using a single dimensional array like arrayTable[i] = 5;, it wouldn't have mattered. Because the last value of arrayTable[i] is irrelevant in that case. Javascript will just add the element to the array.

    But the problem arises when you are using multi-dimensional arrays.
    Your code is trying to access arrayTable[i][j] which is basically undefined[j].
    This is not possible. Which is exactly what the error is telling you.

    You need to make sure your arrayTable has at least row number of rows. Or you can push a new array at the end of table before each iteration.
    In any case, you have to make sure a row exists before trying to use it.

  • Default User Avatar

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

  • Default User Avatar

    Hello, I'm not really sure what the "fixnum" requirement means - I'm using Javascript.
    I've tried converting to int and float a variety of ways and always pass the value test but still fail: "TypeError: Cannot set property '0' of undefined at multiplicationTable"

    Can anyone offer a bit of advice?

    Thanks!

  • Default User Avatar

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

  • Custom User Avatar

    Could you post your entire code (just mark it as spoiler)?
    I tried the kata and it's working for me.
    And it's really difficult to locate the problem in the code with only an if statement.

  • Default User Avatar

    Hey guys, this is ongoing for a number of days now.I've completely restarted this from scratch five times now and google a billion ways of finding out if an array is null. It is clear to me now that array2 in test five is null and as indicated in the comment above I can return any random thing OTHER THAN false (ie, 5, 0, -1, even the string "false" <- which does not satisfy the test) without getting a timeout error. This is Extreeeeemely frustrating now!!

  • Custom User Avatar

    I'm not exactly sure what is expected to return if the arrays are empty. I tried just not doing anything regarding checking if it was empty since it said "If a or b are empty the result is evident by itself." But then I have 'undefined' for a few cases when I submit.

    I added in a check for if the array is empty, and I'm not sure if it's supposed to return true or false, because either way I get an error i.e. when I put to return true, there's an error saying I should get false, then when I switch it to return false, I get an error saying I should return true.

    Can I have a different explanation of the expectation for empty arrays other than "If a or b are empty the result is evident by itself"?

  • Default User Avatar

    I'm having a really strange issue where I can't return false without getting a timeout error! (using javascript)

    I can return 4 or "elephants" or "false" and the test completes fine but as soon as I type: return false;
    I get an error

    this is after an if statement:
    if(array2 == null || array1 == null)
    {
    return false; // once again, here return 4; or return "false"; work no problem... :/
    }

    Thanks for any advice you can offer!