Created
November 29, 2018 03:07
-
-
Save frankyaorenjie/14f31c128955ac5ceab6ecda222c9786 to your computer and use it in GitHub Desktop.
utils #nodejs #typescriopt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class Utils { | |
uniqArray(a: object[]) { | |
return Array.from(new Set(a)); | |
} | |
uniqObjectArrayByKey(a: object[], k: any) { | |
return a.filter((obj, pos, arr) => { | |
return arr.map(mapObj => mapObj[k]).indexOf(obj[k]) === pos; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment