Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
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:
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.
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);
}
});
});
"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.
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.
This comment is hidden because it contains spoiler information about the solution
I'm so sorry for this. I'm working in improving my skills.
well, this is a way to do it I guess.