public FilterResponse ProcessSort(FilterResponse stringResponse) { var error = ValidateInputString(stringResponse.InputString); if (error != null) { return(new FilterResponse(error)); } FilterResponse cleanString = SortString(stringResponse.InputString); return(cleanString); }
private FilterResponse SortString(string inputString) { FilterResponse stringResponse = new FilterResponse(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) { sortString = string.IsNullOrEmpty(sortString) ? ia.ToString() : sortString + "," + ia.ToString(); } stringResponse.InputString = sortString; return(stringResponse); }
private FilterResponse FilterString(string inputString) { FilterResponse stringResponse = new FilterResponse(inputString); int[] iaArr = inputString.Split(',').Select(n => Convert.ToInt32(n)).ToArray(); string cleanString = string.Empty; foreach (int ia in iaArr) { if (!IsPrime(ia)) { cleanString = string.IsNullOrEmpty(cleanString) ? ia.ToString() : cleanString + "," + ia.ToString(); } } stringResponse.InputString = cleanString; return(stringResponse); }