Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is some experimental code that i just came up with and its native javascript.</p> <p><strong>First Define a function that compares two arrays.</strong></p> <pre><code>function compareArrays( val_one, val_two ) { var arr_one = val_one, arr_two = val_two; if ( arr_one.length !== arr_two.length ) return false; for ( var i = 0; i &lt; arr_one.length; i++ ) { if( arr_one[i] !== arr_two[i] ) return false; } return true; } </code></pre> <p>**Also define a function that merges two objects</p> <pre><code>function mergeObjects( obj_1, obj_2 ) { var a = obj_1, b = obj_2; for ( prop in b ) { if ( !a[prop] ) { a[prop] = b[prop]; } else if ( prop === 'encounter_bits' ) { a[prop]['rarity'] += b[prop]['rarity']; } } return a; } </code></pre> <p><strong>Let us traverse our array</strong></p> <pre><code>for ( var i=0; i&lt;arr.length; i++ ) { // loop over the array that holds objects. if(arr[i] !== null){ // if object has not been used var _min = arr[i].encounter_bits.min_level, _max = arr[i].encounter_bits.max_level, _con = arr[i].encounter_bits.conditions; //create variables that hold values you want to compare for ( var c = 0; c &lt; arr.length; c++ ) { /* create an inner loop that will also traverse the array */ if ( c !== i &amp;&amp; arr[c] !== null ) { // if inner loop is not on current loop index if ( _min === arr[c].encounter_bits.min_level &amp;&amp; _max === arr[c].encounter_bits.max_level &amp;&amp; compareArrays(_con, arr[c].encounter_bits.conditions) ) { var newObject = mergeObjects(arr[i], arr[c]); arr[i] = newObject; arr[c] = null; } } } } } </code></pre> <p>Please let me know if it works.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload