Advertisement
andreadc

typesCount

Apr 20th, 2020
1,612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* questo codice conta quanti tipi di auto esistono nella gallery.
  2. è tipo il count in ebay, quello che riguarda i filtri.
  3. es. coupè(2), jeep(4), sportive(6).
  4. */
  5. let cars = this.filteredCars.value;
  6. let types = this.types.value;
  7.    
  8. for(let j=0;j<types.length;j++){
  9.    
  10.     let count = 0;
  11.  
  12.     for(let k=0;k<cars.length;k++){
  13.    
  14.         if(types[j].name == cars[k].type)
  15.             count++;
  16.         }
  17.    
  18.         types[j].count = count;
  19.    
  20.     }
  21.    
  22.    this.types.next(types);
  23.  
  24. }
  25.  
  26. /* qui di sotto il codice che ho riscritto io.
  27. mi da errore 'types.map is not a function'.
  28. non so se sia corretto il resto,
  29. ci sarà almento un'altro errore sempre che non sia sbagliato il concetto.
  30. */
  31.  
  32. combineLatest(this.filteredCars, this.types)
  33.     .pipe(
  34.         map((filteredCars:any, types:any) => {
  35.           filteredCars.map( (fc) => types.map( (ty:TypeCB) => ty.name == fc.type ? ty.count++ : null))
  36.         }),
  37.         tap(() => console.log('piped'))
  38.     ).subscribe();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement