Simple logic in javascript

Posted by Saurabh on Stack Overflow See other posts from Stack Overflow or by Saurabh
Published on 2010-06-14T04:58:52Z Indexed on 2010/06/14 5:02 UTC
Read the original article Hit count: 181

Filed under:

I have four variables of type integer -

var tip_1, tip_2, tip_3, tip_4;

The value of these variables are getting fill by some other logic which is always between 1 to 10. I need to maintain a hash with variable name as "key" and value as "value" by following these rules -

  1. The variable with MAX value should be the first element in the hash and so on. e.g. if tip_1 = 4, tip_2 = 1, tip_3 = 2, tip_4 = 10 then hash should be something like, Hash = {tip_4, 10} {tip_1, 4} {tip_3, 2} {tip_1, 1}

  2. In case of tie following order should be considered - tip_1 > tip_2 > tip_3 > tip_4;

© Stack Overflow or respective owner

Related posts about JavaScript