Hi there,

Here is my @Pipe for a specific Array, i think that it can be far far 
faster in the way to write it so i would like to see how i can improve it : 
I use it in a mat-optgroup in a mat-autocomplete to have folders(dossier) 
sorted and subfolders (datas here) too.

@Pipe({name: 'search2'})
export class TopBarPipe implements PipeTransform {
  transform(dossier, searchTerm: string): any {
    if(!dossier) return [];
    var copy = [];
    for (var i = 0; i < dossier.length; i++) {
      var foundDossier = 0;
      if (~dossier[i].name.toLowerCase().indexOf(searchTerm.toLowerCase()) 
&& !foundDossier) {
        foundDossier = 1;
        copy.push(dossier[i]);
      }
      if (!foundDossier) {
        for (var j = 0; j < dossier[i].datas.length; j++) {
          if 
(~(dossier[i].datas[j].designationProduit.toLowerCase()).indexOf(searchTerm.toLowerCase()))
 
{
            if (copy.length === 0) {
              var newDossier = {};
              newDossier.datas = [];
              newDossier.name = dossier[i].name;
              newDossier.datas.push(dossier[i].datas[j]);
              copy.push(newDossier);
            }
            else {
              for (var k = 0; k < copy.length; k++) {
                if (copy[k].name === dossier[i].datas[j].idDossier) {
                  copy[k].datas.push(dossier[i].datas[j]);
                }
                else {
                  var newDossier = {};
                  newDossier.datas = [];
                  newDossier.name = dossier[i].name;
                  newDossier.datas.push(dossier[i].datas[j]);
                  copy.push(newDossier);
                }
              }
            }
          }
        }
      }
    }
    return copy;
  }
}

The array is attachment.  


Thank you all

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to