Find the largest difference
2022年5月1日小于 1 分钟
Find the largest difference
Question
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
Code
/**
* @param {number[]} arr
* @return {number}
*/
function largestDiff(arr) {
// your code here
}