DEV Community

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

Collapse
 
clandau profile image
Courtney

TypeScript

export function countPositivesSumNegatives(input: number[]) : number[] {
  let positiveCount = 0, negativeSum = 0;
  if(!input || !input.length) return [];
  for(let num of input) {
      if(num <= 0) negativeSum += num;
      else positiveCount++;
    }
  return [positiveCount, negativeSum];
}