Skip to content

Instantly share code, notes, and snippets.

@frankyaorenjie
Created November 29, 2018 03:07
Show Gist options
  • Save frankyaorenjie/14f31c128955ac5ceab6ecda222c9786 to your computer and use it in GitHub Desktop.
Save frankyaorenjie/14f31c128955ac5ceab6ecda222c9786 to your computer and use it in GitHub Desktop.
utils #nodejs #typescriopt
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