Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Finding two or more matching largest values in an array.

1. ## Finding two or more matching largest values in an array.

Hi I am currently writing a program to analyse (to a degree), the points scored in a dance contest. The program mainly works so far. However I am struggling to conclude the program end. Using an if statement, I would like to compute if a dance-off is required, looping through the combinedPointsArray and determining if 2 or more numbers hold the higest score and are equal.

The aim is to provide:
1. Maximum number of combined points
2. The couples and their combined points
3. The couples names with the highest points
4. If two or more couples have equal highest combined points - output whether a dance-off is required.

This is my program so far:

Code:
```<HTML>
<TITLE>
Latin Dancing Contest
</TITLE>

<SCRIPT LANGUAGE = "JavaScript">

var contestantNamesArray = ['Tom and Nazia', 'Pat and Dan', 'Sandra and Kofi', 'Ian and Adele', 'Paul and Costas'];

var judgesPointsArray = [2,1,5,4,3];
var audiencePointsArray = [4,5,2,3,1];
var combinedPointsArray = new Array (judgesPointsArray.length)

for (x=0;x<combinedPointsArray.length;x++)
{
combinedPointsArray[x] = parseInt( judgesPointsArray[x] +  audiencePointsArray[x] );
}

var biggest = 0;
var values = new Array();

for (x=0;x<combinedPointsArray.length;x++)

{
if (combinedPointsArray[x] >= biggest )
{
values[biggest]++;
biggest = parseInt(combinedPointsArray[x]);
}

}

if ( values == biggest )
{
document.write('A Dance-off is required <BR><BR> ');
}

document.write('The biggest score was : ' + (biggest));

</script>

<BR><BR>
<table border="1">
<tr><th>Names</th><th>Combined Points</th></tr>

<script language="JavaScript">
<!--
// Use a for loop to step through the two arrays and print
// the values in the table.
for (var i=0; i<contestantNamesArray.length; i++)
{
document.write("<tr><td>" + contestantNamesArray[i] + "</td>");
document.write("<td>" + combinedPointsArray[i] + "</td></tr>");
}
//-->

</script>

<BODY>
</BODY>
</HTML>```
Any help would be really appreciated. I have spent so long on this; consequently I am pulling my hair out.

Regards

hyp3r

2. Have you tried the Search feature of this forum? We have done this homework already this semester.

It is your responsibility to die() if necessary….. - PHP Manual

3. ## Users who have thanked Philip M for this post:

Hyp3r (07-10-2010)

4. Thank you, I did try the search function but to no avail.

5. Code:
```<HTML>
<TITLE>
Latin Dancing Contest
</TITLE>

<SCRIPT LANGUAGE = "JavaScript">

var contestantNamesArray = ['Tom and Nazia', 'Pat and Dan', 'Sandra and Kofi', 'Ian and Adele', 'Paul and Costas'];

var judgesPointsArray =   [2,1,5,4,3];
var audiencePointsArray = [4,5,2,3,1];
var combinedPointsArray = [];

for (var x=0;x<contestantNamesArray.length;x++){
combinedPointsArray[x] = [contestantNamesArray[x],judgesPointsArray[x] +  audiencePointsArray[x]];
}

var biggest = 0;
var values = [];

for (var x=0;x<combinedPointsArray.length;x++){
if (combinedPointsArray[x][1]>= biggest ){
biggest = combinedPointsArray[x][1];
}
}

for (var x=0;x<combinedPointsArray.length;x++){
if (combinedPointsArray[x][1]== biggest ){
values.push(combinedPointsArray[x][0]);
}
}

if (values.length>1){
document.write('A Dance-off is required <BR><BR> ');
document.write(values.join('<BR>')+'<BR><BR>');
}

document.write('The biggest score was : ' + biggest);

</script>

<BR><BR>
<table border="1">
<tr><th>Names</th><th>Combined Points</th></tr>

<script language="JavaScript">
<!--
// Use a for loop to step through the two arrays and print
// the values in the table.
for (var i=0; i<contestantNamesArray.length; i++)
{
document.write("<tr><td>" + combinedPointsArray[i][0] + "</td>");
document.write("<td>" + combinedPointsArray[i][1] + "</td></tr>");
}
//-->

</script>

<BODY>
</BODY>
</HTML>```

6. ## Users who have thanked vwphillips for this post:

Hyp3r (07-10-2010)

7. Although the 'homework' had been done before. I wanted to do it from scratch. You certainly don't learn anything by copying. Also I took the initiative to post the contestantsNamesArray + combinedPointsArray in a table. Much neater imo.

p.s I don't mind admitting I'm a newbie at programming.

Year 1 of my BSc computing and systems practice degree