Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Count of positives / sum of negatives

// Given an array of integers.
// 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.

function countPositivesSumNegatives(input) {
  let totalCount = [0, 0]
    if(input === null || input.length <= 0) totalCount = []
    else{
      input.forEach(number => {
          if(number > 0) totalCount[0] += 1
          else totalCount[1] += number
      })
    }
    return totalCount;
}

// With love @kouqhar
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript canvas grayscale 
Javascript :: check to see if work is uppercase javascript 
Javascript :: javascript hashmap 
Javascript :: .ajax how to get data from form 
Javascript :: onselect javascript 
Javascript :: react and react dom cdn 
Javascript :: angular get current route 
Javascript :: nodejs how to send html 
Javascript :: sum elements in list with same name js 
Javascript :: angular delete with body 
Javascript :: past value from parent in reactjs 
Javascript :: how to download express without view 
Javascript :: js largest number in array 
Javascript :: Angular Laravel has been blocked by CORS policy: Request header field x-requested-with is not allowed by Access-Control-Allow-Headers in preflight response. 
Javascript :: loop an object in javascript 
Javascript :: collapse uncollapse jquery 
Javascript :: On pressing enter change the focus to the next input field 
Javascript :: determine if array has duplicates lodash 
Javascript :: react native navigation header right 
Javascript :: javascript queryselector child element 
Javascript :: cypress check attribute for each element 
Javascript :: vs code shows bodyparser deprecated 
Javascript :: binary gap 
Javascript :: react router dom v6 active link 
Javascript :: how to show 1 to 10 odd numbers in javascript 
Javascript :: js password generator 
Javascript :: how to use svg in react js 
Javascript :: lyrics api 
Javascript :: sequelize order with include 
Javascript :: how to send enter event to input field jquery 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =