𝓥𝓪𝓵𝓮𝓷𝓽𝓲𝓷𝓪.🌸
count positives and sum of negatives
hi, im doing an excercise that given an array of integers, I have to return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. 0 is neither positive nor negative. If the input is an empty array or is null, return an empty array.
i've been on this excercise for over 30 minutes but i cant figure out how to do the last step (If the input is an empty array or is null, return an empty array.) can someone help me out figuring out what im missing/ doing wrong?
=============
using System;
using System.Collections.Generic;
using System.Linq;
public class Kata
{
public static int[] CountPositivesSumNegatives(int[] input)
{
if ((input.Length == 0) || (input == null))
{
;
return new int [] {};
}
else{
int pos = 0;
int neg = 0;
foreach (int i in input)
{
if (i > 0)
{
pos += 1;
}
else if (i <= 0){
neg += i;
}
}
if ((pos == 0) && (neg == 0))
{
int [] result = {};
return result;
}
else{
int [] result = {pos, neg};
return result;
}
}
//return an array with count of positives and sum of negatives
}
}
18 replies