Very simple question: I'm trying to compare values in an array and I'm completely stumped as to why my comparison logic is failing. Somehow, during the course of my loop, 6 is being evaluated as > 524. Any ideas as to what I'm doing wrong? I'm totally stumped. Here's the code, and thanks!
function highAndLow(numbers){
var compArr = numbers.split(" ");
var highNum = compArr[0]
var lowNum = compArr[0];
for (i = 1; i < compArr.length; i++) {
if (compArr[i] > highNum) {
highNum = compArr[i]
console.log(highNum)
}
}
for (i = 1; i < compArr.length; i++) {
if (compArr[i] < lowNum) {
lowNum = compArr[i]
}
}
return highNum + " " + lowNum
}
highAndLow("4 5 29 54 4 0 -214 542 -64 1 -3 6 -6")
Again, I'm not sure how, but the result I'm getting in the console is 6 for the highNum (incorrect) and -214 for the lowNum (which is correct). Am I missing something obvious?