jquery - Checking Key Value Pairs in Javascript -


i have business scenario below.

i adding rows of possible (key, value) pairs.(country, climate) 1 below.

in image 2 whole scenario valid , invalid (key, value) given.


possible keys - country, india, australia, america, england

possible values - climate, hot, dry, rainy, cold, humid


for example

if (all country, climate) chosen first pair (england, hot) should not allowed chosen second pair

if (all country, hot) chosen first pair (india, hot) should not allowed bechosen second pair

if (america, climate) chosen first pair (america, hot) should not allowed chosen second pair

where

if (india, hot) chosen first pair (india, humid) shall allowed chosen second pair

if (america, climate) chosen first pair (england, climate) shall be allowed chosen second pair

if (america, climate) chosen first pair (india, humid) shall allowed chosen second pair

image 1

image1


image 2

image2

question have explained colleague valid , invalid possible combinations through image2.

in javascript simplest solution add if else statements , getting done.by doing gap between 1 explained solve business scenario in paper , code widens.

what best implementation of transferring matrix in paper code business in paper , code have close relation.

this question may sound vague @ least once faced issue things written solve problem in paper , way solved code makes no sense.

use binary arithmetic.

country values

india       0001 australia   0010 america     0100 england     1000 country 1111 

climate value

hot         00001 dry         00010 rainy       00100 cold        01000 humid       10000 climate 11111 

when choose second item, use and operation decide if value choosen, (all or same value).

example

var firstcountry = 0xf var secondcountry = 0x1 if ( (firstcountry & secondcountry) > 0) {     console.log("country choosen"); } 

of course example 1 attribute. should update both attributes.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -