filmov
tv
Program 13 Find the Smallest number from an array | Math.min() | Array sort | Arrays

Показать описание
1. Using for loop:-
-------------------
To find the smallest number in JavaScript from the given array [12, 09, 45, 78, 67, 09], you can use a for loop and comparison, as it has a time complexity of O(n) (linear time). This approach only requires iterating over the array once and comparing each element with the current smallest number.
----------------------------
3. Sort:-
--------
the sort() method is used to sort the array in ascending order. The sort() method takes a compare function as a parameter, which determines the order in which the elements are sorted. The compare function subtracts a from b to sort the elements in ascending order.
After the array is sorted, the smallest number is assigned to the minValue variable, which is the first element of the sorted array.
-------------------
To find the smallest number in JavaScript from the given array [12, 09, 45, 78, 67, 09], you can use a for loop and comparison, as it has a time complexity of O(n) (linear time). This approach only requires iterating over the array once and comparing each element with the current smallest number.
----------------------------
3. Sort:-
--------
the sort() method is used to sort the array in ascending order. The sort() method takes a compare function as a parameter, which determines the order in which the elements are sorted. The compare function subtracts a from b to sort the elements in ascending order.
After the array is sorted, the smallest number is assigned to the minValue variable, which is the first element of the sorted array.