Answers for "how to get smallest number in array javascript"

3

js find lowest number in array

const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4]
const min = arr.reduce((a, b) => Math.min(a, b))
console.log(min)
Posted by: Guest on April-18-2021
2

find smallest number in array js

//Not using Math.min:
const min = function(numbers) {
  let smallestNum = numbers[0];
for(let i = 1; i < numbers.length; i++) {
    if(numbers[i] < smallestNum) {
      smallestNum = numbers[i];   
    }
  }
return smallestNum;
};
Posted by: Guest on January-05-2021
1

how to find the smallest two numbers in an array javascript

function sumTwoSmallestNumbers(numbers) {  
  numbers = numbers.sort((a, b) => {
    return a - b; });
};  //this will turn the numbers list into the 2 lowest numbers
Posted by: Guest on October-08-2020

Code answers related to "how to get smallest number in array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language