Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more

Works for unknown number of int[]

Code
Diff
  • using System;
    using System.Linq;
    
    public static class Kata
    {
      public static int ArraySum(params int[][] arrs)
      {
        int sum = 0;
        foreach (int[] arr in arrs)
        {
            sum += arr.Sum();
        }
        return sum;
      }
    }
    
  • 1- using System;
    1+using System;
    22 using System.Linq;
    33
    4- public static class Kata
    5- {
    6- public static int ArraySum(int[] arr1, int[] arr2, int[] arr3)
    7- {
    8- int[] newArray1 = arr1.Concat(arr2).ToArray();
    9- int[] newArray2 = newArray1.Concat(arr3).ToArray();
    10- int sum = newArray2.Sum();
    11- return sum;
    12- }
    4+public static class Kata
    5+{
    6+ public static int ArraySum(params int[][] arrs)
    7+ {
    8+ int sum = 0;
    9+ foreach (int[] arr in arrs)
    10+ {
    11+ sum += arr.Sum();
    12+ }
    13+ return sum;
    14+ }
    1313 }