1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < title > Bubble Test</ title >
5+ < script type ="text/javascript ">
6+ var scores = [ 60 , 50 , 60 , 58 , 54 , 54 ,
7+ 58 , 50 , 52 , 54 , 48 , 69 ,
8+ 34 , 55 , 51 , 52 , 44 , 51 ,
9+ 69 , 64 , 66 , 55 , 52 , 61 ,
10+ 46 , 31 , 57 , 52 , 44 , 18 ,
11+ 41 , 53 , 55 , 61 , 51 , 44 ] ;
12+
13+ var costs = [ .25 , .27 , .25 , .25 , .25 , .25 ,
14+ .33 , .31 , .25 , .29 , .27 , .22 ,
15+ .31 , .25 , .25 , .33 , .21 , .25 ,
16+ .25 , .25 , .28 , .25 , .24 , .22 ,
17+ .20 , .25 , .30 , .25 , .24 , .25 ,
18+ .25 , .25 , .27 , .25 , .26 , .29 ] ;
19+
20+ function getAndPrintHighestScore ( scoresX ) {
21+ //var scores.length = scores.length;
22+ var highScoreX = 0 ;
23+
24+ for ( var i = 0 ; i < scoresX . length ; i ++ ) {
25+ document . write ( "Bubble soluntion " + i + "# " + "scores: " + scoresX [ i ] + "<br>" ) ;
26+ if ( scoresX [ i ] > highScoreX ) {
27+ highScoreX = scoresX [ i ] ;
28+ }
29+ }
30+
31+ return highScoreX ;
32+ }
33+
34+ var highScore = getAndPrintHighestScore ( scores ) ;
35+ document . write ( "Bubble Tests: " + scores . length + "<br>" ) ;
36+ document . write ( "Highest Bubble score: " + highScore + "<br>" ) ;
37+
38+ function getBestResults ( score1 , highScore1 ) {
39+ var scoreIndex = [ ] ;
40+ for ( var i = 0 ; i < score1 . length ; i ++ ) {
41+ if ( score1 [ i ] == highScore1 ) {
42+ scoreIndex . push ( i ) ;
43+ }
44+ }
45+ return scoreIndex ;
46+ }
47+
48+ var scoreIndex1 = getBestResults ( scores , highScore ) ;
49+ document . write ( "solution with highest Bubble score is: " + scoreIndex1 + "<br>" ) ;
50+
51+ function getMostCostEffectiveSolution ( scoresZ , costsZ , highScoreZ ) {
52+ var cost = 100 ;
53+ var index = 0 ;
54+
55+ for ( var i = 0 ; i < scoresZ . length ; i ++ ) {
56+ if ( scoresZ [ i ] == highScoreZ ) {
57+ if ( cost > costsZ [ i ] ) {
58+ index = i ;
59+ cost = costsZ [ i ] ;
60+ }
61+ }
62+ }
63+
64+ return index ;
65+ }
66+
67+ var mostCostEffective = getMostCostEffectiveSolution ( scores , costs , highScore ) ;
68+
69+ document . write ( "Bubble Solution #" + mostCostEffective + " is the most cost effective" ) ;
70+ </ script >
71+ </ head >
72+ < body >
73+
74+ </ body >
75+ </ html >
0 commit comments