Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

You are getting a `numbers` array. Return the sum of **negative** numbers only. //condition to check for negative

function SummPositive( numbers ) {
  var negatives = [];
  var sum = 0;

  for(var i = 0; i < numbers.length; i++) {
    if(numbers[i] < 0) {
      negatives.push(numbers[i]);
    }else{
      sum += numbers[i];
    }
  }

  console.log(negatives);

  return sum;
}

var sum_result = SummPositive( [ 1, 2, 3, 4, 5, -2, 23, -1, -13, 10,-52 ] );

console.log(sum_result);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript moving text from left to right onscroll 
Javascript :: javqascript sarray push method 
Javascript :: using the for of loop in pure javascript to populate data into HTML 
Javascript :: how to print array of 52/ print it 5 times with different value in javascript 
Javascript :: js palindrome number 
Javascript :: for each add character javascript 
Javascript :: bootstrap 4 without javascript 
Javascript :: london turnbridgewells 
Javascript :: eachfeature leaflet 
Javascript :: synthetic linkText 
Javascript :: how to push into an array javascript 
Javascript :: The Scratch Semicolon Glitch 
Javascript :: what is from npm 
Javascript :: click on list item javascript highlight 
Javascript :: javascript terminal base64 encoder 
Javascript :: laravel vuejs barcode 
Javascript :: intro to graphs with js 
Javascript :: node command get to much time 
Javascript :: js increment safety value html 
Javascript :: processing map in javascript 
Javascript :: domdocument::save() getting permission errors 
Javascript :: karma error parent child 
Javascript :: js replace blogger thumb 
Javascript :: append rotated triangle in anchor tag 
Javascript :: show ... in 2nd line javascript 
Javascript :: compare string camelcase and lowercase javascript 
Javascript :: how to create monorapo project in angular 8 
Javascript :: js return undefined on ReferenceError 
Javascript :: Target type ieee.std_logic_1164.STD_LOGIC_VECTOR in variable assignment is different from expression type ieee.std_logic_1164.STD_ULOGIC. 
Javascript :: momentDurationFormatSetup 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =