Loading...
Engaged Employer
How to display the maximum and minimum values in an array?
Anonymous
Using sorting algorithm sort the array and display the last and zeroth index elements of array
const numbers = [5, 10, 2, 8, 15, 1]; let maxNumber = numbers[0]; let minNumber = numbers[0]; for (let i = 1; i maxNumber) { maxNumber = numbers[i]; } if (numbers[i] < minNumber) { minNumber = numbers[i]; } } console.log("Maximum number:", maxNumber); console.log("Minimum number:", minNumber);
Check out your Company Bowl for anonymous work chats.
Get actionable career advice tailored to you by joining more bowls.
Stay ahead in opportunities and insider tips by following your dream companies.
Get personalized job recommendations and updates by starting your searches.