Can someone help me understand why my function isn’t returning the highest and lowest elements in an array. I originally set the high and low to arr[0] and try to iterate through the array and changing the values of high and low in comparison to the variable “low” and “high”
function getTheRange(arr){
var low = arr[0]
var high = arr[0]
var newArr = []
for (let i = 0; i < arr.length; i++) {
if (arr[i] < low) {
low === arr[i]
}
else if (arr [i] > high) {
high === arr[i]
}
}
var range = high - low
newArr.push(low, high, range)
return newArr
// ADD CODE HERE
}
// Uncomment these to check your work!
console.log(getTheRange([3, 2, 5, 4, 7, 9, 10])); // expect log [2, 10, 8]