• + 0 comments
    using CategoryGroup = System.Collections.Generic.Dictionary<Category, int>;
    
    enum Category {
        Positive,
        Negative,
        Zero
    }
    
    class Result
    {
    
        /*
         * Complete the 'plusMinus' function below.
         *
         * The function accepts INTEGER_ARRAY arr as parameter.
         */
    
        public static void plusMinus(List<int> arr)
        {
            
            
            var total = arr.Count();
            CategoryGroup counts = new CategoryGroup
            {
                { Category.Positive, 0 },
                { Category.Negative, 0 },
                { Category.Zero, 0 },
            };
            
            
            arr.ForEach(n => {
               if(n > 0) counts[Category.Positive]++;
               else if(n<0) counts[Category.Negative]++;
               else counts[Category.Zero]++;
            });
            
            printCounts(counts, total);
        }
        
        private static void printCounts(CategoryGroup counts, int total)
            => counts.Keys.ToList().ForEach(key 
                => Console.WriteLine(
                        calcFraction(counts[key], total)
                    )
                );
        private static string calcFraction(int countOf, int total) => 
            ((double) countOf / total).ToString("F6");
    
    }