DEV Community

Discussion on: Daily Coding Puzzles - Oct 29th - Nov 2nd

 
dance2die profile image
Sung M. Kim

Thanks for the suggestion there, @asparallel.

Here is the updated C# code (with the same logic as JavaScript one) using .Aggregate.

using System.Linq;
using System;

public class Kata
{
    public static int[] CountPositivesSumNegatives(int[] a)
    {
        return (a == null || a.Length == 0) 
          ? new int[0]
          : a.Aggregate(new [] {0, 0}, (acc, n) => {
              if (n > 0) acc[0]++;
              else acc[1] += n;
              return acc;
            });
    }
}
Enter fullscreen mode Exit fullscreen mode