Ad
  • Custom User Avatar
  • Custom User Avatar

    You're well-educated to tell it

  • Custom User Avatar

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

  • Default User Avatar

    Definitely something wring with the random tests (I failed 20 of them after passing all of the basic tests):

    Small Arrays
    arr1: [34, 38, 7, 6, 4, 46, 17, 36, 33, 45, 1, 47, 13, 14, 11, 32, 20, 9, 49, 18, 21, 35, 19, 40]
    arr2: [33, 2, 30, 46, 15, 5, 20, 11, 0, 24, 50, 6, 37, 16, 13, 29, 44, 32, 21, 1, 12, 35]
    ✘ Expected: [0, 26, 14, 12], instead got: [10, 26, 14, 12]

    The intersection of the two arrays is [6, 46, 33, 1, 13, 11, 32, 20, 21, 35] for a length of 10.

    Confirmed with minitest on my local machine:

    def test_random_example
    arr1 = [34, 38, 7, 6, 4, 46, 17, 36, 33, 45, 1, 47, 13, 14, 11, 32, 20, 9, 49, 18, 21, 35, 19, 40]
    arr2 = [33, 2, 30, 46, 15, 5, 20, 11, 0, 24, 50, 6, 37, 16, 13, 29, 44, 32, 21, 1, 12, 35]
    assert_equal(process_2arrays(arr1, arr2), [10, 26, 14, 12])
    end

    Running:

    .

    Finished in 0.001227s, 814.9959 runs/s, 814.9959 assertions/s.

    1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

  • Custom User Avatar

    (see previous comments)

    redid the KATA and removed the duplicate entries and the code worked.

  • Custom User Avatar

    For the designer of this KATA, I hope this information is helpful to you:

    I did this KATA using JavaScript and experienced odd results......so:

          I modified it to test for empty arrays (for either arr1 and/or arr2) so that the result 
          could be populated with a minimum of calculations.
    
          I also used two for loops that used indexOf to see if an element of one array exists in the other.
          I did this in order to avoid the complication of sorting and/or checking for duplicate elements.
    

    What should have resulted is the code should have worked regardless of empty arrays and/or duplicate data. What actually resulted was I still received a boatload of errors on the test results.

    I then console logged the array values within the test results to see what was actually being conveyed
    as arguments to arr1 & arr2 and tested my code fully outside of the codewars environment
    and it executed perfectly.

    I am fairly certain that there is an issue with your test cases.

  • Custom User Avatar

    I have rebuilt Random test cases as it should be:

    describe("Random Cases", function(){
    it("Challenging Cases", function(){
    var arr1, arr2, length, i, elem, result, res;
    for (var h = 0; h <= 100; h++) {
    arr1 = [];
    length = randint(10, 5000);
    for (i = 0; i <= length; i++) {
    elem = randint(0, 1500);
    if (arr1.indexOf(elem) < 0) arr1.push(elem);
    }
    arr2 = [];
    length = randint(10, 5000);
    for (i = 0; i <= length; i++) {
    elem = randint(0, 1500);
    if (arr2.indexOf(elem) < 0) arr2.push(elem);
    }
    result = process2ArraysRandomCases(arr1, arr2);
    res = process2Arrays(arr1, arr2);
    Test.assertSimilar(res, result);
    }
    });
    });

  • Custom User Avatar

    "We need a function that receives two arrays arr1 and arr2, each of them, with elements that OCCUR ONLY ONCE."

    But in test cases (javascript version) elements occur NOT only once.
    It was neccessary to prefilter arr1 to solve this kata:

    arr1 = arr1.reduce((arr, el) => arr.indexOf(el) > -1 ? arr : (arr.push(el), arr), arr1.slice(0,0));

    Only after that filtering I have passed all the test cases.

  • Custom User Avatar

    "I'm looking so cool today"

    Expected: 5, instead got: 6

    1)I
    2)m (short form from "am")
    3)looking
    4)so
    5)cool
    6)today

  • Custom User Avatar

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

  • Custom User Avatar

    The javascript version has been just released, two hours ago. Let me check it to find th bug

  • Custom User Avatar

    ...
    return [arr1.length, arr2.length];

    Expected: '[0, 1494, 1494, 0]', instead got: '[3999, 0]'

    arr1.length === 3999,
    arr2.length === 0,

    So how did you get [0, 1494, 1494, 0] ?

    I think there is a mistake in Random Cases (javascript version).

  • Custom User Avatar

    Javascript:
    6 static cases passed successfully,
    but all 101 challenging cases failed.

    For example:
    Expected: '[0, 1480, 1480, 0]', instead got: '[0, 4333, 4333, 0]'

    But actually arr1.length is 4333, arr2.length is 0, so we should get:
    (1) ---> 0 # because the elements present in both arryas are: none
    (2) ---> 4333 # beacause elements present in only one array are: arr1.length
    (3) ---> 4333 # elements remaning of arr1 are: 1, 3, 5, 7, 9: arr1.length
    (4) ---> 0 # elements remaning of arr2 are: arr2.length === 0

    So what is wrong with JS Random cases?