blob: e8c134b0de3a647e754889d0387bf294970e48bb [file] [log] [blame]
/*
******************************************************************************
* Copyright © 2018 PTA GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************
*/
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'unique'
})
export class UniquePipe implements PipeTransform {
transform(items: any[], fieldName: string): any[] {
const cArray = [];
if (!items) {
return [];
}
return items.filter((item, index, arr) => {
const itemExists = cArray.find(ia => {
return ia === item[fieldName];
}
);
if ((item[fieldName] || item[fieldName] === 0) && !itemExists && itemExists !== 0) {
cArray.push(item[fieldName]);
return true;
} else {
return false;
}
});
}
}