I have n arrays with which I need to determine if x is in all n arrays. (where n is any number and x is a numerical value). I have something like the following in place, but it always ends up being false.
function filterArrays()
{
var x = $(this).attr('id');
var arrays = [[1,2,3],[2,4,6]];
var result = false;
for each (var n in arrays)
{
result = result ^ (n.indexOf(x) > -1);
}
}
How to make resultequal truewhen it xis in both arrays, but when xit is not in both arrays, do resultequal false?
The function above will be used with the jQuery method filter(). Example:
$(arrayOfElementsWithNumericIds).filter(arrayFilter);
// arrayOfElementsWithNumericIds prototype: [div
I think bitwise operation is required, but I could be wrong. Please explain why your decision is correct and why mine is not working. (for bonus points)
source
share