How do you find the largest and smallest number for an unsorted integer array in typescript or javascript?

One of the most famous interview questions is:

How do you find the largest and smallest number for an unsorted integer array?

This question relates to data structures. Hence can be implemented using any language or approach. I suggest the typescript or javascript implementation as this:

const numbers = [2, 40, 9, 21, 1, 16, 24];

const smallest = Math.min(...numbers);
const largest = Math.max(...numbers);

console.log('Smallest Value:', smallest); // Smallest Value: 1
console.log('Largest Value:', largest);   // Largest Value: 40


Nordible is a digital solutions provider helping organizations achieve their digital goals.

We develop and measure digital solutions, implement impactful brand promotion and SEO strategies and develop software driven by rigorous testing that help your business succeed online and beyond.

You can contact us at info@nordible.com for business inquiries.

Follow us: