From 2e69a87be1d827cadbf4b6bc6fcd3fabb63b82b9 Mon Sep 17 00:00:00 2001 From: danrevah Date: Sun, 27 Nov 2016 15:29:24 +0200 Subject: [PATCH] intersection --- bin/app/pipes/array/intersection.d.ts | 2 +- bin/app/pipes/array/intersection.js | 7 +++++-- bin/app/pipes/array/intersection.js.map | 2 +- package.json | 2 +- src/app/pipes/array/intersection.spec.ts | 10 +++++----- src/app/pipes/array/intersection.ts | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/bin/app/pipes/array/intersection.d.ts b/bin/app/pipes/array/intersection.d.ts index c65ce2e2..7603152e 100644 --- a/bin/app/pipes/array/intersection.d.ts +++ b/bin/app/pipes/array/intersection.d.ts @@ -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[]; } diff --git a/bin/app/pipes/array/intersection.js b/bin/app/pipes/array/intersection.js index e972c1d5..f4647f8d 100644 --- a/bin/app/pipes/array/intersection.js +++ b/bin/app/pipes/array/intersection.js @@ -12,8 +12,11 @@ var core_1 = require('@angular/core'); var IntersectionPipe = (function () { function IntersectionPipe() { } - IntersectionPipe.prototype.transform = function (arr, args) { - if (args === void 0) { args = []; } + IntersectionPipe.prototype.transform = function (arr) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } return args.reduce(function (newArr, currArr) { return newArr.filter(function (elm) { return !!~currArr.indexOf(elm); }); }, arr); diff --git a/bin/app/pipes/array/intersection.js.map b/bin/app/pipes/array/intersection.js.map index 1302846e..7a23da98 100644 --- a/bin/app/pipes/array/intersection.js.map +++ b/bin/app/pipes/array/intersection.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/app/pipes/array/intersection.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qBAA8C,eAAe,CAAC,CAAA;AAI9D;IAAA;IAOA,CAAC;IALC,oCAAS,GAAT,UAAU,GAAS,EAAE,IAAe;QAAf,oBAAe,GAAf,SAAe;QAClC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAC,MAAM,EAAE,OAAO;YAC/B,OAAA,MAAM,CAAC,MAAM,CAAC,UAAA,GAAG,IAAI,OAAA,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAvB,CAAuB,CAAC;QAA7C,CAA6C,EAC/C,GAAG,CAAC,CAAC;IACT,CAAC;IARH;QAAC,iBAAU,EAAE;QACZ,WAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAC,CAAC;;wBAAA;IAQ7B,uBAAC;AAAD,CAPA,AAOC,IAAA;AAPY,wBAAgB,mBAO5B,CAAA","file":"intersection.js","sourcesContent":["import {PipeTransform, Pipe, Injectable} from '@angular/core';\n\n@Injectable()\n@Pipe({name: 'intersection'})\nexport class IntersectionPipe implements PipeTransform {\n\n transform(arr:any[], args:any[] = []):any[] {\n return args.reduce((newArr, currArr) =>\n newArr.filter(elm => !!~currArr.indexOf(elm))\n , arr);\n }\n}\n"]} \ No newline at end of file +{"version":3,"sources":["../src/app/pipes/array/intersection.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qBAA8C,eAAe,CAAC,CAAA;AAI9D;IAAA;IAOA,CAAC;IALC,oCAAS,GAAT,UAAU,GAAU;QAAE,cAAc;aAAd,WAAc,CAAd,sBAAc,CAAd,IAAc;YAAd,6BAAc;;QAClC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAC,MAAM,EAAE,OAAO;YAC/B,OAAA,MAAM,CAAC,MAAM,CAAC,UAAA,GAAG,IAAI,OAAA,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAvB,CAAuB,CAAC;QAA7C,CAA6C,EAC7C,GAAG,CAAC,CAAC;IACX,CAAC;IARH;QAAC,iBAAU,EAAE;QACZ,WAAI,CAAC,EAAC,IAAI,EAAE,cAAc,EAAC,CAAC;;wBAAA;IAQ7B,uBAAC;AAAD,CAPA,AAOC,IAAA;AAPY,wBAAgB,mBAO5B,CAAA","file":"intersection.js","sourcesContent":["import {PipeTransform, Pipe, Injectable} from '@angular/core';\n\n@Injectable()\n@Pipe({name: 'intersection'})\nexport class IntersectionPipe implements PipeTransform {\n\n transform(arr: any[], ...args: any[]): any[] {\n return args.reduce((newArr, currArr) =>\n newArr.filter(elm => !!~currArr.indexOf(elm))\n , arr);\n }\n}\n"]} \ No newline at end of file diff --git a/package.json b/package.json index 542bd268..b6c56c2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng2-pipes", - "version": "0.4.9", + "version": "0.4.10", "author": "Dan Revah", "description": "Useful angular2 pipes", "license": "MIT", diff --git a/src/app/pipes/array/intersection.spec.ts b/src/app/pipes/array/intersection.spec.ts index eeb6840f..f5995d0a 100644 --- a/src/app/pipes/array/intersection.spec.ts +++ b/src/app/pipes/array/intersection.spec.ts @@ -1,4 +1,4 @@ -import {IntersectionPipe} from "./intersection"; +import {IntersectionPipe} from './intersection'; describe('IntersectionPipe', () => { let pipe: IntersectionPipe; @@ -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]); }); }); diff --git a/src/app/pipes/array/intersection.ts b/src/app/pipes/array/intersection.ts index aa13b713..1443d964 100644 --- a/src/app/pipes/array/intersection.ts +++ b/src/app/pipes/array/intersection.ts @@ -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); } }