<script>
// let min =;
// let max = ;
function minMax(array) {
let min = 0;
let max = 0;
for (let i = 0; i < array.length; i++) {
array[i] < min && min = array[i];
array[i] > max && max = array[i];
}
}
</script>
VS Code says there are two problems, ‘;’ is expected, but I’ve already provided the ‘;’.
enter image description here
I don’t know what to do, a if sentence can avoid this issue, but I’d like to know why the above way isn’t working.
If you want to do that, you should wrap it with parentheses
array[i] < min && (min = array[i]);
array[i] > max && (max = array[i]);
The part on the left of the
=
is where the data on the right of the=
will be stored. How would you storearray[i]
inside of the expressionarray[i] < min && min
? It doesn’t make sense, which is why that’s an error. I think you just have what each side is for confused.btw, your starting values should be better the first value of the array instead of zero. if you do not want to take them, you could
Number.MAX_VALUE
and the negative value of it.@NinaScholz Or just
-Infinity