Ad
  • Custom User Avatar
  • Custom User Avatar

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

  • 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

    There are a couple of issues with the javascript version with the random test cases.
    You are told in the details of the kata that the function "receives two arrays arr1 and arr2, each of them, with elements that occur only once",
    however the random arrays will generate repeated values into the arrays which need to be accounted for and it's not clear that is neccesary to removed/ignore them to solve the kata.
    Additionally, the second array is always empty in the random test cases.

  • Custom User Avatar

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

  • Custom User Avatar

    I'm so sorry for this. I'm working in improving my skills.

  • Custom User Avatar

    well, this is a way to do it I guess.