Click here to Skip to main content
14,330,663 members
Rate this:
Please Sign up or sign in to vote.
See more:
[ 'a', 2 ]
[ 'b', 2 ]
[ 'c', 2 ]
[ 'd', 2 ]
[ 'e', 3 ]
[ 'f', 2 ]
[ 'g', 2 ]
[ 'h', 2 ]


Here i want to compare this map[key,value] by value.....here e = 3.....all values are 2...so it would be e = (3-1)......if and only if all values are same and if any value greater than 1 from all value remove that value by 1 and again remap it and print it so all value be same...


if any value difference is greater than 1....so we will not print it.





Note that :- In the code char_count is the variable which get value from count_frequency function....which i did not include here.

What I have tried:

var flag = 0;
 var myMap = new Map();

    for(let [key,value] of myMap)
    {
        console.log([key,value]);


         if(value == char_count)
         {
           
             flag = 1;
        //    console.log([key,value]);
            
         }
          if(value == 2)
         {
             value =  value-1;
             myMap.set([key,value]);

            
         }
        
        
    }
    
    if(flag == 1)
    {
        return "YES";
    }
    else
    {
        return "NO";
    }
Posted
Updated 9-Oct-19 23:39pm
v2
Comments
CPallini 10-Oct-19 6:15am
   
Could you please rephrase your requirements? Do you wnt to remove an item only if its value is exactly one unity bigger than all the other values? What should happen if there are values not conforming to this (e.g. bigger more than one unity, smaller, etc..)?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100