import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: "orderBy"
})

export class OrderByPipe {

    constructor() {}
    
    result: any;

    transform(array: any, string: string): any {

        if(string) {

            for(let product of array) {
                for(let attribute of product.attributes) {
                    if(attribute.code == 'type') {
                        if(string == attribute.value) {
                            this.result.push(product);
                        }
                    }
                }
            }
            
        } else {
            this.result = array;
        }

    }
}