예제 #1
0
        private StringResponse FilterString(string inputString)
        {
            StringResponse stringResponse = new StringResponse(inputString);

            int[] iaArr = inputString.Split(',').Select(n => Convert.ToInt32(n)).ToArray();

            string cleanString = string.Empty;

            foreach (int ia in iaArr)
            {
                if (!IsPrime(ia))
                {
                    if (string.IsNullOrEmpty(cleanString))
                    {
                        cleanString = ia.ToString();
                    }
                    else
                    {
                        cleanString = cleanString + "," + ia.ToString();
                    }
                }
            }
            stringResponse.InputString = cleanString;
            return(stringResponse);
        }
예제 #2
0
        public StringResponse ProcessSort(StringResponse stringResponse)
        {
            var error = ValidateInputString(stringResponse.InputString);

            if (error != null)
            {
                return(new StringResponse(error));
            }
            StringResponse cleanString = SortString(stringResponse.InputString);

            return(cleanString);
        }
예제 #3
0
        private StringResponse SortString(string inputString)
        {
            StringResponse stringResponse = new StringResponse(inputString);

            int[] iaArr = inputString.Split(',').Select(n => Convert.ToInt32(n)).ToArray();
            iaArr = iaArr.OrderByDescending(c => c).ToArray();
            String sortString = string.Empty;

            foreach (int ia in iaArr)
            {
                if (string.IsNullOrEmpty(sortString))
                {
                    sortString = ia.ToString();
                }
                else
                {
                    sortString = sortString + "," + ia.ToString();
                }
            }
            stringResponse.InputString = sortString;
            return(stringResponse);
        }