Answers for "finding the smallest number in an array javascript"

14

max value in array javascript

// For large data, it's better to use reduce. Supose arr has a large data in this case:
const arr = [1, 5, 3, 5, 2];
const max = arr.reduce((a, b) => { return Math.max(a, b) });

// For arrays with relatively few elements you can use apply: 
const max = Math.max.apply(null, arr);

// or spread operator:
const max = Math.max(...arr);
Posted by: Guest on November-27-2020
1

javascript removing smallest number in array

function removeSmallest(arr) {
    var min = Math.min(...arr);
    return arr.filter(e => e != min);
}
Posted by: Guest on March-29-2020
10

javascript find smallest number in an array

const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4]
const min = Math.min(...arr)
console.log(min)
Posted by: Guest on February-16-2020
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 smallest number in array js

Array.min = function( array ){
    return Math.min.apply( Math, array );
};
Posted by: Guest on November-25-2020
-2

finding the smallest number in an array javascript

var arr = [5,1,9,5,7];
var smallest = arr[0];

for(var i=1; i<arr.length; i++){
    if(arr[i] < smallest){
        smallest = arr[i];   
    }
}

console.log(smallest);
Posted by: Guest on January-02-2021

Code answers related to "finding the smallest number in an array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language