107. Find the largest difference

JavaScriptAlgorithm
Is this helpful ?

easy  - accepted / - tried

Given an array of numbers, pick any two numbers a and b, we could get the difference by Math.abs(a - b).

Can you write a function to get the largest difference?


largestDiff([-1, 2,3,10, 9])
// 11,  obviously Math.abs(-1 - 10) is the largest

largestDiff([])
// 0

largestDiff([1])
// 0

Let's try to solve this problem within 10 minutes.

Discuss(50)