How to get largest and smallest number in an array?



How to get largest and smallest number in an array?..

Answer / Nitin

In JavaScript, you can use the Math.min() and Math.max() functions along with the spread operator (...) to find the minimum and maximum values of an array. Example: const arr = [1, 2, 3]; console.log({ min: Math.min(...arr), max: Math.max(...arr) });

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

What is difference between tree and forest?

1 Answers  


How would you dynamically allocate a one-dimensional and two-dimensional array of integers?

1 Answers  


What is a undirected graph?

1 Answers  


Differentiate linear from a nonlinear data structure?

1 Answers  


Explain Array

1 Answers   Tech Mahindra,


Which collection class is thread safe?

1 Answers  


What is binary search in data structure?

1 Answers  


What are the two traversal strategies used in traversing a graph?

1 Answers  


There are 8, 15, 13, 14 nodes were there in 4 different trees. Which of them could have formed a full binary tree?

1 Answers  


What are the four types of variables?

1 Answers  


Is treemap sorted?

1 Answers  


Is array a dynamic data structure?

1 Answers  


Categories