Finding range of an array

Finding range of an array
0.0 0

#1

I’m looking to write a function function range (arr) which takes an array, finds the highest and lowest value of that array, subtracts those values and return the total. So for example, the array [6,2,3,4,9,6,1,0,5]) would return 8, as 9 is the highest, 1 is the lowest, and then would subtract the two.

Any help would be greatly appreciated.

Cheers


#2

You may want to look into the Math.max and Math.min functions, along with the spread operator to get them to work for arrays.


#3

got it!! thanks man really appreciate it