After creating two sets of arrays and passing them into different functions, I noticed some strange behavior. The first time I called the functions for scores1, everything worked perfectly. Likewise, the second time I called the first function (for Scores2), it also worked without any issues. However, things took a bizarre turn when I called the second function again for Scores2. It started displaying results from the previous call for Scores1 instead. Even more puzzling was that it recognized only two high scores instead of three, but somehow managed to pick them from the other array.
Any help or insight on this matter would be greatly appreciated,
Rob.
var scores1 = [20, 40, 44, 50, 66, 56, 44, 69, 69, 65, 45, 56, 67, 55, 45, 32, 49, 59, 60, 62, 65, 55, 66, 69, 57, 68, 66, 61, 65];
var scores2 = [31, 60, 44, 55, 66, 56, 44, 69, 69, 65, 45, 56, 67, 55, 74, 32, 49, 59, 60, 62, 65, 74];
function printAndGetHighScore(scores) {
var highScore = 0;
var output;
for (var i = 0; i < scores.length; i++) {
output = "Bubble solution #" + i + " score: " + scores[i];
console.log(output);
if (scores[i] > highScore) {
highScore = scores[i];
}
}
return highScore;
}
function getHighestScores(scores) {
var highestScores = [];
for (var i = 0; i < scores.length; i++) {
if (scores[i] == highScore1) {
highestScores.push(i);
}
}
return highestScores;
}
var highScore1 = printAndGetHighScore(scores1);
console.log("Bubble tests: " + scores1.length);
console.log("Highest bubble score: " + highScore1);
var highestScores1 = getHighestScores(scores1);
console.log("Highest scoring solutions: " + highestScores1);
var highScore2 = printAndGetHighScore(scores2);
console.log("Bubble tests: " + scores2.length);
console.log("Highest bubble score: " + highScore2);
var highestScores2 = getHighestScores(scores2);
console.log("Highest scoring solutions: " + highestScores2);