Skip to content

Commit 8601e1c

Browse files
committed
updates
1 parent c72f8ac commit 8601e1c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

chapter4/bubbles.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@
4848
}
4949
}
5050
console.log("Solutions with the highest score: " + bestSolutions);
51+
52+
53+
// Actually Frank was right; you can do it one loop.
54+
// But it's more complex. Here's how:
55+
for (var i = 0; i < scores.length; ++i){
56+
output = "Bubble solution #" + i + " score:" + scores[i];
57+
console.log(output);
58+
if (scores[i] > highScore){
59+
highScore = scores[i];
60+
bestSolutions = [i];
61+
} else if (scores[i] == highScore){
62+
bestSolutions.push(i);
63+
}
64+
}
65+
console.log("Best solutions: " + bestSolutions);
66+
67+
5168
</script>
5269
</head>
5370
<body>

chapter4/bubbles2.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868

6969
function getMostCostEffectiveSolution(scores, costs, highScore) {
70-
var cost = 100.00; // much higher than any of the costs
70+
var cost = 100; // much higher than any of the costs
7171
var index;
7272

7373
for (var i = 0; i < scores.length; i++) {
@@ -87,7 +87,7 @@
8787
// This is a little more efficient, but not quite as easy to read!
8888
//
8989
function getMostCostEffectiveSolution2(bestSolutions, costs, highScore) {
90-
var cost = 100.0;
90+
var cost = 100;
9191
var solutionIndex;
9292
var lowCostIndex;
9393

0 commit comments

Comments
 (0)