We are required to write a JavaScript function that takes in an array of numbers. The function should pick the greatest and lowest value from the array and return their difference.
Example
const arr = [4, 6, 3, 1, 5, 8, 9, 3, 4]; const difference = (arr = []) => { const highest = Math.max(...arr); const lowest = Math.min(...arr); return highest - lowest; }; console.log(difference(arr));
Output
And the output in the console will be −
8