I am placing markers on a Google map. I have a number of checkboxes (19 currently) in a form that I am trying to create a dynamic \"and\" condition to display or not display
An approach where you did not have to iterate over each q-property of the marker:
Use bitwise operations.
Lets assume you have a marker with the properties q1, q3 and q5 set to true .
Instead of storing each property of the marker, use a decimal and set the bytes 1,3 and 5.
This would result in the binary value 10101
(the decimal is 21
, store it as the marker-property)
To compare this decimal with the checked checkboxes use also a decimal and set the bytes where the checkboxes are checked.
Assuming the checkboxes for q1 and q5 are checked, the binary value would be 10001
(decimal 17
)
All you have to do now is to check if the result of a bitwise AND
of the markers property and the checkboxes-property is equal to the checkboxes-property
((21 & 17)>>>0===17)//returns true
This approach would work for up to 32 properties.
Demo: http://jsfiddle.net/doktormolle/hsPVS/