arrays - Compare divs(class) in parents and if missing add them to right place javascript -


need searching , adding algoritm javascript code compare divs(classes) in parents , if missing add them right place...

<div class="score">   <div class="system">     <div class="stff_flute"></div>     <div class="stff_timpani"></div>   </div>   <div class="system">     <div class="stff_flute"></div>   </div>   <div class="system">     <div class="stff_timpani"></div>   </div>   <div class="system">     <div class="stff_flute"></div>     <div class="stff_timpani"></div>   </div> </div> 

to...

<div class="score">   <div class="system">     <div class="stff_flute"></div>     <div class="stff_timpani"></div>   </div>   <div class="system">     <div class="stff_flute"></div>     <div class="stff_timpani"></div>   </div>   <div class="system">     <div class="stff_flute"></div>     <div class="stff_timpani"></div>   </div>   <div class="system">     <div class="stff_flute"></div>     <div class="stff_timpani"></div>   </div> </div> 

maybe way throught array comparing cannot figure out.. https://jsfiddle.net/e5b1gots/8/

i solved problem :)

//--- find instrument ---//    function comparearrays(a, b) {      return !a.some(function (e, i) {          return e != b[i];      });  }  var = [];  $('.system > div').each(function(){      var all_instruments = $(this).attr('class');      a.push(all_instruments);  });  var filter = function(value, index){ return this.indexof(value) == index };  var filtereddata = a.filter(filter, );  var = filtereddata;  console.log(a);  $('.score > div').each(function(){      b = [];      $("> div",this).each(function(){       var all_instruments2 = $(this).attr('class');       b.push(all_instruments2)  });    //--- add missing instrument ---//    c = a.filter(function(val) {    return b.indexof(val) == -1;  });  (i = 0; < a.length; i++) {    c = c.sort(a);    $('<div class="'+ (c[i]) +'">'+ (c[i]) +'</div>').appendto(this);    $(".undefined").remove();  }  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <div class="score">    <div class="system">      <div class="stff_flute">stff_flute</div>      <div class="stff_timpani">stff_timpani</div>    </div>    <div class="system">      <div class="stff_flute">stff_flute</div>    </div>    <div class="system">    <div class="stff_oboe">stff_oboe</div>      <div class="stff_timpani">stff_timpani</div>    </div>    <div class="system">      <div class="stff_flute">stff_flute</div>      <div class="stff_oboe">stff_oboe</div>      <div class="stff_timpani">stff_timpani</div>    </div>  </div>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -