Skip to content

Commit 2426b7b

Browse files
committed
Code style : move generic array functions together at end of file.
1 parent 837bc93 commit 2426b7b

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

scratch/chapter4/bubble.html

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,7 @@
3232

3333

3434

35-
function computeMaximum(arrayOfNumbers){
36-
37-
var maximum = 0;
38-
for (var i = 0; i < arrayOfNumbers.length; i++) {
39-
40-
if (arrayOfNumbers[i] > maximum) {
41-
maximum = arrayOfNumbers[i];
42-
}
43-
}
44-
45-
return maximum;
46-
};
35+
4736

4837
function oneLineRepresentationOfSolution(index, score, price, highScore) {
4938

@@ -69,23 +58,7 @@
6958

7059
};
7160

72-
/**
73-
* Return an array containing zero or more indexes into the
74-
* arrayOfNumbers such that arrayOfNumbers[ index ] == valueToMatch.
75-
*/
76-
function indexesWithValue(arrayOfNumbers, valueToMatch) {
77-
78-
var indexes = [];
79-
80-
// find the indexes having that highest score
81-
for (var i = 0; i < arrayOfNumbers.length; i++) {
82-
if (arrayOfNumbers[i] == valueToMatch) {
83-
indexes.push(i);
84-
}
85-
}
86-
87-
return indexes;
88-
};
61+
8962

9063
function indexesOfCheapestSolutionsWithHighestScore(scores, prices) {
9164

@@ -114,6 +87,40 @@
11487
return cheapestSolutionsWithHighScore;
11588
};
11689

90+
91+
// Generic Array functions.
92+
93+
/**
94+
* Return an array containing zero or more indexes into the
95+
* arrayOfNumbers such that arrayOfNumbers[ index ] == valueToMatch.
96+
*/
97+
function indexesWithValue(arrayOfNumbers, valueToMatch) {
98+
99+
var indexes = [];
100+
101+
// find the indexes having that highest score
102+
for (var i = 0; i < arrayOfNumbers.length; i++) {
103+
if (arrayOfNumbers[i] == valueToMatch) {
104+
indexes.push(i);
105+
}
106+
}
107+
108+
return indexes;
109+
};
110+
111+
function computeMaximum(arrayOfNumbers){
112+
113+
var maximum = 0;
114+
for (var i = 0; i < arrayOfNumbers.length; i++) {
115+
116+
if (arrayOfNumbers[i] > maximum) {
117+
maximum = arrayOfNumbers[i];
118+
}
119+
}
120+
121+
return maximum;
122+
};
123+
117124
</script>
118125
</head>
119126
<body>

0 commit comments

Comments
 (0)