I’d like to make a call to another jQuery function and pass another argument – the argument I pass depends on the name of the argument that was passed to the original function. So i might have something like this:
matchedNumbers1 = compareArrays(userNumbers, winningNumbers1, matchedNumbers1);
matchedNumbers2 = compareArrays(userNumbers, winningNumbers2, matchedNumbers2);
matchedNumbers2 = compareArrays(userNumbers, winningNumbers3, matchedNumbers2);
//COMPARE INPUTTED ARRAY OF NUMBERS TO WINNING ARRAYS OF NUMBERS
function compareArrays (userInput, winningNums, matches) {
matches = 0;
allMatchedNumbers.length = 0;
$(userInput).each(function(i) {
$(winningNums).each(function(j) {
if (userInput[i] == winningNums[j]) {
allMatchedNumbers[matches] = userInput[i];
matches++;
}
});
});
switch (winningNums) {
case 'winningNumbers1':
alert("!!!!!");
markMatches(ListItems1);
break;
case 'winningNumbers2':
markMatches(ListItems2);
break;
case 'winningNumbers3':
markMatches(ListItems3);
break;
}
return matches;
}
Hopefully the code above makes it clear what i’m trying to do. I tried using a switch statement but this only compares the value and not the name of the original argument that was passed to the function. Any help would be appreciated.
You shouldn’t be doing that, even if you could. Just pass in the array that you want to match against as another argument: