Ad
  • Custom User Avatar

    [javascript]. My code is getting failed test cases when they should be passing. For example, I get this error message:

    should work for random perfect powers

    your pair (40, 6) doesn't work for 4097152081 - Expected: 4097152081, instead got: 4096000000

    when in fact Math.pow(40, 6) = 4096000000. And also:

    should return valid pairs for random inputs

    your pair (33, 3) doesn't work for 35947 - Expected: 35947, instead got: 35937

    but again Math.pow(33, 3) = 35937

  • Custom User Avatar

    I'm doing this kata in Javascript. My code is getting failed test cases when they should be passing. For example, I get this error message:

    should work for random perfect powers

    your pair (40, 6) doesn't work for 4097152081 - Expected: 4097152081, instead got: 4096000000

    when in fact Math.pow(40, 6) = 4096000000. And also:

    should return valid pairs for random inputs

    your pair (33, 3) doesn't work for 35947 - Expected: 35947, instead got: 35937

    but again Math.pow(33, 3) = 35937

  • Custom User Avatar
  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    Here's my code:

    function sumArray(array) {
    if (array === null || array.length == 0 || array.length == 1)
    return 0;
    return array.sort(function(a,b){return a-b}).slice(1, -1).reduce(function(a,b){return a+b});
    }

    When submitted, I get 3 passed tests and one error saying "TypeError: Reduce of empty array with no initial value at Array.reduce at sumArray". Why am I getting this error?