Skip to main content
added 7 characters in body
Source Link
Evariste
  • 9.7k
  • 2
  • 21
  • 30

You don't need to pass count as a parameter as you can get it from queries Inside the method RecursiveNestedOr itself (also, rename parameter query as queries).

Otherwise, your recursion looks fine to me. Here's how I'd "simplified" it, using LINQ (add using System.Linq):

public static string RecursiveNestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

    // Now queries.Count is at least 2
    return CAMLQueryBuilder.QueryOr(queries.Last(), RecursiveNestedOr(queries.Take(queries.Count() - 1)));
}

EDIT:
HowHere's how to do it without recursion (code not tested):

public static string NestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

   string result = queries.First();

   // Now queries.Count is at least 2

   foreach(string query in queries.Skip(1))
   {
      result = QueryOr(result, query);
   }

    return result;
}

You don't need to pass count as a parameter as you can get it from queries Inside the method RecursiveNestedOr itself (also, rename parameter query as queries).

Otherwise, your recursion looks fine to me. Here's how I'd "simplified" it, using LINQ (add using System.Linq):

public static string RecursiveNestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

    // Now queries.Count is at least 2
    return CAMLQueryBuilder.QueryOr(queries.Last(), RecursiveNestedOr(queries.Take(queries.Count() - 1)));
}

EDIT:
How to do it without recursion (code not tested):

public static string NestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

   string result = queries.First();

   // Now queries.Count is at least 2

   foreach(string query in queries.Skip(1))
   {
      result = QueryOr(result, query);
   }

    return result;
}

You don't need to pass count as a parameter as you can get it from queries Inside the method RecursiveNestedOr itself (also, rename parameter query as queries).

Otherwise, your recursion looks fine to me. Here's how I'd "simplified" it, using LINQ (add using System.Linq):

public static string RecursiveNestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

    // Now queries.Count is at least 2
    return CAMLQueryBuilder.QueryOr(queries.Last(), RecursiveNestedOr(queries.Take(queries.Count() - 1)));
}

EDIT:
Here's how to do it without recursion (code not tested):

public static string NestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

   string result = queries.First();

   // Now queries.Count is at least 2

   foreach(string query in queries.Skip(1))
   {
      result = QueryOr(result, query);
   }

    return result;
}
added 554 characters in body
Source Link
Evariste
  • 9.7k
  • 2
  • 21
  • 30

You don't need to pass count as a parameter as you can get it from queries Inside the method RecursiveNestedOr itself (also, rename parameter query as queries).

Otherwise, your recursion looks fine to me. Here's how I'd "simplified" it, using LINQ (add using System.Linq):

public static string RecursiveNestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

    // Now queries.Count is at least 2
    return CAMLQueryBuilder.QueryOr(queries.Last(), RecursiveNestedOr(queries.Take(queries.Count() - 1)));
}

EDIT:
How to do it without recursion (code not tested):

public static string NestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

   string result = queries.First();

   // Now queries.Count is at least 2

   foreach(string query in queries.Skip(1))
   {
      result = QueryOr(result, query);
   }

    return result;
}

You don't need to pass count as a parameter as you can get it from queries Inside the method RecursiveNestedOr itself (also, rename parameter query as queries).

Otherwise, your recursion looks fine to me. Here's how I'd "simplified" it, using LINQ (add using System.Linq):

public static string RecursiveNestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

    // Now queries.Count is at least 2
    return CAMLQueryBuilder.QueryOr(queries.Last(), RecursiveNestedOr(queries.Take(queries.Count() - 1)));
}

You don't need to pass count as a parameter as you can get it from queries Inside the method RecursiveNestedOr itself (also, rename parameter query as queries).

Otherwise, your recursion looks fine to me. Here's how I'd "simplified" it, using LINQ (add using System.Linq):

public static string RecursiveNestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

    // Now queries.Count is at least 2
    return CAMLQueryBuilder.QueryOr(queries.Last(), RecursiveNestedOr(queries.Take(queries.Count() - 1)));
}

EDIT:
How to do it without recursion (code not tested):

public static string NestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

   string result = queries.First();

   // Now queries.Count is at least 2

   foreach(string query in queries.Skip(1))
   {
      result = QueryOr(result, query);
   }

    return result;
}
added 6 characters in body
Source Link
Evariste
  • 9.7k
  • 2
  • 21
  • 30

You don't need to pass count as a parameter as you can get it from queries Inside the method RecursiveNestedOr itself (also, rename parameter query as queries).

Otherwise, your recursion looks fine to me. Here's how I'd "simplified" it, using LINQ (add using System.Linq):

public static string RecursiveNestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

    // Now queries.Count is at least 2
    return CAMLQueryBuilder.QueryOr(queries.Last(), RecursiveNestedOr(queries.Take(queries.Count() - 1)));
}

You don't need to pass count as a parameter as you can get it from queries Inside the method RecursiveNestedOr itself (also, rename parameter query as queries).

Otherwise, your recursion looks fine to me. Here's how I'd "simplified" it, using LINQ (add using System.Linq):

public static string RecursiveNestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count == 0)
        return "";

   if (queries.Count == 1)
       return queries.First();

    // Now queries.Count is at least 2
    return CAMLQueryBuilder.QueryOr(queries.Last(), RecursiveNestedOr(queries.Take(queries.Count - 1)));
}

You don't need to pass count as a parameter as you can get it from queries Inside the method RecursiveNestedOr itself (also, rename parameter query as queries).

Otherwise, your recursion looks fine to me. Here's how I'd "simplified" it, using LINQ (add using System.Linq):

public static string RecursiveNestedOr(IEnumerable<string> queries)
{
    if (queries == null || queries.Count() == 0)
        return "";

   if (queries.Count() == 1)
       return queries.First();

    // Now queries.Count is at least 2
    return CAMLQueryBuilder.QueryOr(queries.Last(), RecursiveNestedOr(queries.Take(queries.Count() - 1)));
}
Source Link
Evariste
  • 9.7k
  • 2
  • 21
  • 30
Loading