0

Why doesn't continue work for the first element in the array?

https://code.sololearn.com/WGtQJYiBCN2H/?ref=app Here I return the difference between the minimum and maximum values in the array by only checking the numerical values in the array. If an element in the array is not a number, it must continue to the next element. But if I keep the first element of the array as a 'string', the continue statement doesn't seem to work and instead breaks out of the loop and returns the difference between the string or the first element in the array. Why does this happen and this doesn't seem to happen if the 'string' value is kept in the middle or at the end of the array.

10th Apr 2022, 5:31 PM
Srinath
3 Antworten
+ 2
You probably need to find a valid (numeric) value first, before you can begin comparing elements. A while...loop is probably worth implementing [Pseudo] while element at index <i> is non numeric increment <i> Let minValue & maxValue be element at index <i> Begin comparison starting from index <i> + 1, exclude <i> cause it's already used as index for minValue & maxValue. (Edit) If <i> goes past the last index, we know there's no numeric data.
10th Apr 2022, 10:37 PM
Ipang
+ 1
You are comparung arr[0] which is a string with other values for max, and min.. Note: you set min=max= arr[0] edit: try this way: set let max=0; let min; and use if(min == undefined || curTemp < min) min=curTemp
10th Apr 2022, 5:41 PM
Jayakrishna 🇮🇳