У меня есть эта таблица ввода, которая показывает коды стран и зоны, связанные с каждым кодом страны.
<!DOCTYPE html>
<html>
<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=170 style='width:102.0pt;margin-left:-.05pt;border-collapse:collapse'>
<tr style='height:.2in'>
<td width=170 nowrap colspan=2 valign=bottom style='width:102.0pt;border:
solid windowtext 1.0pt;background:#BF8F00;padding:0in 5.4pt 0in 5.4pt;
height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><b><span style='color:black'>ZONES
TABLE</span></b></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#305496;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><b><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:white'>COUNTRY CODE</span></b></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#305496;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><b><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:white'>ZONE</span></b></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>237</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>CMR</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>1721</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>SXM2</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>124622</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>BRB1</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>334</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>FRA3</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>124624</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>BRB3</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>124</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>BRB45</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>1246</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>BRB7</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>1876</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>JAM</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>358</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>FIN</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>33751</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>FRA1</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>33679</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>FRA2</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>599</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>ANT</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>61</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>AUS</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>230</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>MUS</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>31</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>NLD</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>65</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>SGP</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>1721</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>SXM4</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>1</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>USA</span></p>
</td>
</tr>
<tr style='height:.2in'>
<td width=122 style='width:73.0pt;border:solid windowtext 1.0pt;border-top:
none;background:#FAFAFA;padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>124623</span></p>
</td>
<td width=48 style='width:29.0pt;border-top:none;border-left:none;border-bottom:
solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;background:#FAFAFA;
padding:0in 5.4pt 0in 5.4pt;height:.2in'>
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal'><span style='font-size:8.0pt;
font-family:"Verdana",sans-serif;color:black'>BRB2</span></p>
</td>
</tr>
</table>
</html>
И у меня есть коды в столбце NUMBERS следующей таблицы, для которых я хочу найти соответствующую ЗОНУ из таблицы выше. В таблице ниже столбец ZONE будет выводом, который я пытаюсь получить для значений в столбце NUMBERS.
<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC;
}
.tableizer-table th {
background-color: #BF8F00;
color: #FFF;
font-weight: bold;
}
.tableizer-table tr:nth-child(even){background-color: #f2f2f2}
.tableizer-table tr:first-child td {
background-color: #305496; color: #FFF;
}
tr td:nth-child(3) {
background: #DFDFDF;
}
tr:nth-child(1) td:nth-child(3) {
background: #5D5B56;
}
</style>
<table class="tableizer-table">
<thead><tr class="tableizer-firstrow"><th>NUMBERS to SEARCH</th><th>ZONE EXPECTED</th><th> </th></tr></thead><tbody>
<tr><td>NUMBERS</td><td>ZONE</td><td>NOTES about logic to match the zone</td></tr>
<tr><td>18763044</td><td>JAM</td><td>CC=1876 belongs to JAM</td></tr>
<tr><td>187635</td><td>JAM</td><td>CC=1876 belongs to JAM</td></tr>
<tr><td>23092</td><td>MUS</td><td>CC=230 belongs to JAM</td></tr>
<tr><td>3162</td><td>NLD</td><td>CC=31 belongs to NLD</td></tr>
<tr><td>38050</td><td>NOT FOUND</td><td>There is no CC that has as prefix 38,380, 3805 etc</td></tr>
<tr><td>33</td><td>FRA3</td><td>There are 3 CC that begins with 33, but 334 selected because is the shortest and belongs to FRA3</td></tr>
<tr><td>49185</td><td>NOT FOUND</td><td>There is no CC that begins with 49,491, etc</td></tr>
<tr><td>51078</td><td>NOT FOUND</td><td>There is no CC that begins with 51,510, etc</td></tr>
<tr><td>1246</td><td>BRB7</td><td>There are 4 CC that begins with 1246, but there is one exact match, CC=1246 that belongs to ZONE BRB7</td></tr>
<tr><td>1721</td><td>SXM2</td><td>There are 2 CC that begins with 1721, but the ZONE to select is that that appears first. In this case SXM2</td></tr>
</tbody></table>
Я поместил значения таблиц в виде массивов, и до сих пор у меня есть код ниже, который определяет значения массива cc, начинается со значений в числах, но вывод далеко
из моего ожидаемого выхода, так как я не уверен, как это сделать. Может быть, кто-то может мне помочь. Заранее спасибо.
cc=["237","1721","124622","334","124624","124","1246","1876","358","33751","33679","599","61","230","31","65","1721","1","124623"]
zones=["CMR","SXM2","BRB1","FRA3","BRB3","BRB45","BRB7","JAM","FIN","FRA1","FRA2","ANT","AUS","MUS","NLD","SGP","SXM4","USA","BRB2"]
numbers=["18763044","187635","23092","3162","38050","33","49185","51078","1246","1721"]
numbers.map{|n|
cc.find {|i| i.start_with?(n) }
}
=> [nil, nil, nil, nil, nil, "334", nil, nil, "124622", "1721"]