function countPositivesSumNegatives(input) { if (!input || !input.length) return [] let positives = 0 let negSum = 0 for(const num of input){ if(num > 0)positives++ else negSum+=num } return [positives, negSum] } //OR function countPositivesSumNegatives(input) { if (!input || !input.length) return [] let countPositive = 0 let sumNegative = 0 for (let i=0; i<input.length; i++) if(input[i] > 0) { countPositive++; } else if(input[i] < 0) { sumNegative += input[i]}; return [countPositive, sumNegative] }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter