find the smallest number from an array
// smallest number from array function solution(num) { let small = num[0]; for (let i = 1; i <= num.length; i++) { if (small > num[i]) { small = num[i] } } console.log("smallest nunber:", small) } solution([3, 1, 4, 6, 5, 7, 3, 2,0,-1])
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);
Source: stackoverflow.com
Find the smallest element in an array
# find the smallest element in an array # Approach: # Sort the array in ascending order. arr = [2,5,1,3,0] # sorted method my_arr = sorted(arr) print(f"The smallest number is {my_arr[0]}") #* USING FOR LOOP smallest = arr[0] for i in range(0,len(arr)): if arr[i] < smallest : smallest = arr[i] print(f"The smallest number is {smallest}")
Find the smallest integer in the array
const findSmallestInt = (args) => { return Math.min(...args) }