I have the following table and need to find
JSFiddle
code
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.text-bold { font-weight: 700; }
table {
margin: 16px 0;
color:#333;
border-width: 1px;
border-color: #666;
border-collapse: collapse;
}
table th {
border-width: 1px;
padding: 4px;
border-style: solid;
border-color: #666;
background-color: #FBDD9B;
}
table td {
border-width: 1px;
padding: 4px;
border-style: solid;
border-color: #666;
background-color: #fff;
}
</style>
</head>
<body>
<table id="table-results">
<tr>
<th>Question</th>
<th>inovation</th>
<th>all-round</th>
<th>coordination</th>
<th>keeper</th>
<th>analytic</th>
</tr>
<tr>
<td>I.</td>
<td>D=2</td>
<td>A=1</td>
<td>E=10</td>
<td>C=8</td>
<td>B=4</td>
</tr>
<tr>
<td>II.</td>
<td>A=6</td>
<td>C=1</td>
<td>B=2</td>
<td>D=5</td>
<td>E=1</td>
</tr>
<tr>
<td>III.</td>
<td>E=4</td>
<td>B=1</td>
<td>D=3</td>
<td>A=2</td>
<td>C=7</td>
</tr>
<tr>
<td>Suma</td>
<td class="sum">12</td>
<td class="sum">3</td>
<td class="sum">15</td>
<td class="sum">15</td>
<td class="sum">12</td>
</tr>
</table>
</body>
</html>
In the example above the result should look like this
Suma 12 3 15 15 12
Other possible results
Suma 0 0 0 10 0
Suma 12 3 15 7 9
Suma 1 3 15 15 12
Suma 12 3 15 9 12
Suma 4 4 4 4 4
It's actually a little bit complicated, you have to get an array with the numbers from the .sum
elements, then find the highest number, then remove all those from the array, then find the next highest number, and finally target all elements containing those two numbers.
In code, that would look like
var sum = $('.sum');
var arr = sum.map(function(_,x) { return +$(x).text() }).get();
var max = Math.max.apply( Math, arr );
var out = arr.filter(function(x) { return x != max });
var nxt = Math.max.apply( Math, out );
sum.filter(function() {
var numb = +$(this).text();
return numb == max || numb == nxt;
}).css('font-weight', 'bold');
FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With