Tell us what’s happening:
Could someone please help me find the error in my code below… When I run in debugger, and with console logs, I am getting correct answers for each test, but they are still marked with a red x when I run in the browser. Thank you in advance!
Your code so far
var current = [];
var gArguments = {};
var index = 0;
var cleanArgs = [];
//main function
function sym(args) {
cleanArgs = [];
//if first time running set gArguments
if(index === 0){
gArguments = Array.from(arguments);
}
//build test array by concatting current to args
testArray.simplify(args);
testArray.buildTest(cleanArgs);
testArray.runTest(testArray.testVals);
updateArgs(gArguments);
index++;
if (gArguments.length === 0){
current = current.sort(function(a,b){
return a-b;
});
console.log(current);
return current;
} else {
sym(gArguments[0]);
}
}
//included functions
function updateArgs(x) {
for (var i = 0; i < x.length - 1; i++) {
x[i] = x[i + 1];
}
gArguments = x.slice(0, x.length-1);
}
//included objects
var testArray = {
testVals: [],
simplify: function(x){
var temp = [];
for (var i = 0; i <x.length; i++){
if(cleanArgs.indexOf(x[i]) === -1){
cleanArgs.push(x[i]);
}
}
},
buildTest: function(x) {
this.testVals = current.concat(x);
},
runTest: function(x) {
var testArray = [];
for (var i = 0; i < x.length; i++) {
var temp = x.filter(function(val) {
return x[i] === val;
});
testArray.push(temp);
}
current = testArray.filter(function(elem){
return elem.length === 1;
});
for(var i = 0; i < current.length; i++){
current[i] = current[i][0];
}
}
};
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
.
Link to the challenge: