Skip to content

Commit

Permalink
intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
danrevah committed Nov 27, 2016
1 parent ed96ad9 commit 2e69a87
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/app/pipes/array/intersection.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PipeTransform } from '@angular/core';
export declare class IntersectionPipe implements PipeTransform {
transform(arr: any[], args?: any[]): any[];
transform(arr: any[], ...args: any[]): any[];
}
7 changes: 5 additions & 2 deletions bin/app/pipes/array/intersection.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/app/pipes/array/intersection.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng2-pipes",
"version": "0.4.9",
"version": "0.4.10",
"author": "Dan Revah",
"description": "Useful angular2 pipes",
"license": "MIT",
Expand Down
10 changes: 5 additions & 5 deletions src/app/pipes/array/intersection.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IntersectionPipe} from "./intersection";
import {IntersectionPipe} from './intersection';

describe('IntersectionPipe', () => {
let pipe: IntersectionPipe;
Expand All @@ -12,12 +12,12 @@ describe('IntersectionPipe', () => {
});

it('should return empty array if there are no elements in the intersection', () => {
expect(pipe.transform([1, 2, 3], [[4, 5, 6]])).toEqual([]);
expect(pipe.transform([1, 2, 3], [[4, 5, 6], [7, 8, 9]])).toEqual([]);
expect(pipe.transform([1, 2, 3], [4, 5, 6])).toEqual([]);
expect(pipe.transform([1, 2, 3], [4, 5, 6], [7, 8, 9])).toEqual([]);
});

it('should return intersection of arrays', () => {
expect(pipe.transform([1, 2, 3], [[1, 2 ,3, 4, 5, 6]])).toEqual([1,2,3]);
expect(pipe.transform([1, 2, 3], [[1, 2, 4, 5, 6], [1, 2, 7, 8, 9]])).toEqual([1, 2]);
expect(pipe.transform([1, 2, 3], [1, 2 ,3, 4, 5, 6])).toEqual([1,2,3]);
expect(pipe.transform([1, 2, 3], [1, 2, 4, 5, 6], [1, 2, 7, 8, 9])).toEqual([1, 2]);
});
});
4 changes: 2 additions & 2 deletions src/app/pipes/array/intersection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {PipeTransform, Pipe, Injectable} from '@angular/core';
@Pipe({name: 'intersection'})
export class IntersectionPipe implements PipeTransform {

transform(arr:any[], args:any[] = []):any[] {
transform(arr: any[], ...args: any[]): any[] {
return args.reduce((newArr, currArr) =>
newArr.filter(elm => !!~currArr.indexOf(elm))
, arr);
, arr);
}
}

0 comments on commit 2e69a87

Please sign in to comment.