Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to sum to small numbers

function sumTwoSmallestNumbers(numbers) {  
  var min = Number.MAX_SAFE_INTEGER;
  var secondMin = Number.MAX_SAFE_INTEGER;
  
  var n;
  for (i = 0; i < numbers.length; i++) {
    n = numbers[i];
    if(n < min) {
      secondMin = min;
      min = n;
    } else if( n < secondMin ) {
      secondMin = n;
    }
  }
  
  return min + secondMin;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Get year from user entered date in javascript 
Javascript :: Enqueue jquery for TypeError: $.browser is undefined issue 
Javascript :: readmore 
Javascript :: js beutify node.js 
Javascript :: mul function call to 3 functions 
Javascript :: js filter out html 
Javascript :: How to Loop Through an Array with a do…while Loop in JavaScript 
Javascript :: required field in javascript dynamically 
Javascript :: useEffect : react to manipulate the DOM 
Javascript :: Prevent HTTP Parameter Polution in NodeJS 
Javascript :: sap rpa desktop studio activate excel macro 
Javascript :: how to change array elements position in array in javascript 
Javascript :: how to convert javascript to typescript 
Javascript :: how to run json server 
Javascript :: decode jwt token in angular 
Javascript :: redirect router v6 
Javascript :: javascript filter array of object by id 
Javascript :: json stringify without quotes 
Javascript :: how to nested schema mongoose 
Javascript :: javascript number with commas 
Javascript :: if anagram 
Javascript :: creating the find method javascript 
Javascript :: port y build - vite.config.js 
Javascript :: jquery ui sortable between two tables 
Javascript :: javascript include too large or too small numbers 
Javascript :: javascript Error handling is easier to manage 
Javascript :: K= K*7,K=10+K; console.log( K= K/2); 
Javascript :: pizza form validation jquery 
Javascript :: symbol in keyword for arrow below 
Javascript :: phaser place on part of circle 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =