918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Rev | Line | |
---|
[1de07b8a] | 1 | /// @file arrays.js |
---|
| 2 | /// @brief: implementa funciones de uso común para arrays. |
---|
| 3 | /// @date: 2014-10-23 |
---|
| 4 | |
---|
| 5 | /// @function array_interset |
---|
| 6 | /// @brief Devuelve un array con los elementos comunes a los dos arrays iniciales. |
---|
| 7 | /// @brief Los arrays deben estar ordenados. |
---|
| 8 | /// @param 1 {Array} array ordenado. |
---|
| 9 | /// @param 2 {Array} array ordenado. |
---|
| 10 | /// @return {Array} array con elementos comunes. |
---|
| 11 | /// @date: 2014-10-23 |
---|
| 12 | function array_interset (a, b) { |
---|
| 13 | var ai=0, bi=0; |
---|
| 14 | var result = new Array(); |
---|
| 15 | while( ai < a.length && bi < b.length ) |
---|
| 16 | if (a[ai] < b[bi] ){ ai++; } |
---|
| 17 | else if (a[ai] > b[bi] ){ bi++; } |
---|
| 18 | else /* they're equal */ |
---|
| 19 | { |
---|
| 20 | result.push(a[ai]); |
---|
| 21 | ai++; |
---|
| 22 | bi++; |
---|
| 23 | } |
---|
| 24 | return result; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | |
---|
Note: See
TracBrowser
for help on using the repository browser.