Skip to content

Commit 9b11cea

Browse files
committed
Identify and print best solutions.
1 parent 08da2dd commit 9b11cea

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scratch/chapter4/bubble.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,30 @@
1111
46, 31, 57, 52, 44, 18,
1212
41, 53, 55, 61, 51, 44];
1313
var output;
14+
var highScore = 0;
15+
var bestSolutions = [];
1416

17+
// find the highest score
1518
for (var i = 0; i < scores.length; i++) {
1619
output = "Bubble solution #" + i + " score: " + scores[i];
1720
console.log(output);
21+
22+
if (scores[i] > highScore) {
23+
highScore = scores[i];
24+
}
25+
26+
}
27+
28+
29+
console.log("Quantity Bubbles tests: " + scores.length);
30+
console.log("Highest bubble score: " + highScore);
31+
32+
// find the indexes having that highest score
33+
for (var i = 0; i < scores.length; i++) {
34+
if (scores[i] == highScore) {
35+
bestSolutions.push(i);
36+
console.log("Solution #" + i + " is a best solution.");
37+
}
1838
}
1939

2040
</script>

0 commit comments

Comments
 (0)