I have created two sets of arrays and passed them into two functions. The first time I call the functions (for scores1) they work perfectly. The second time I call the first function (for Scores2) it also works perfectly. However, the second time I call the second function (for Scores2) it is bringing up some of the results from the first time I called it (for Scores1). The bizarre thing is, it seems to have realised that there are only two high scores, rather than 3, but has just stolen them from the other array.
Thanks so much in advance for any and all help,
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);
if (scores[i] == highScore1) {<= hard coded variable