Filtering objects according to required and preferred attributes

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
4
down vote

favorite












This my opportunity object which is a part of my angular app.component.ts file. In my template(HTML of this component) I want to loop out different skills backgrounds nationalitiesetc. array using *ngFor*. So I've filtered out these array of objects based on a property option which can have only 2 values either preferred or required. I've implemented such logic inside my TS file using filterByProperty() function as shown below. Please help make this function more simplified and generalized.



opportunity: any = 
"id": 526,
"title": "Testing",
"nationalities": [

"option": "preferred",
"id": 479,
"name": "India",

],
"skills": [

"option": "required",
"id": 1153,
"name": "Adobe Lightroom",
,

"option": "preferred",
"id": 77,
"name": "Python",
,

"option": "preferred",
"id": 78,
"name": "Ajax",
,

"option": "required",
"id": 147,
"name": "3D Max",
,

"option": "preferred",
"id": 175,
"name": "Aircraft Engine Technology",

],
"backgrounds": [

"option": "preferred",
"id": 232,
"name": "Biology",
,

"option": "required",
"id": 249,
"name": "International relations",

],
"languages": [

"option": "required",
"id": 18,
"name": "English",
,

"option": "preferred",
"id": 31,
"name": "Italian",

]



My app.component.ts file



 import Component, OnInit, ViewChild from '@angular/core';

@Component(
selector: 'app-root',
templateUrl: './app.component.html'
)

export class AppComponent implements OnInit

opportunity: any = ; // Object value is shown above
backgrounds: any =
preferred: ,
required:
;
skills: any =
preferred: ,
required:
;
languages: any =
preferred: ,
required:
;
nationalities: any =
preferred: ,
required:
;

ngOnInit()
this.filterByProperty();


filterByProperty()
this.skills.preferred = this.opportunity.skills.filter((i) => i.option === 'preferred');
this.skills.required = this.opportunity.skills.filter((i) => i.option === 'required');
this.backgrounds.preferred = this.opportunity.backgrounds.filter((i) => i.option === 'preferred');
this.backgrounds.required = this.opportunity.backgrounds.filter((i) => i.option === 'required');
this.languages.preferred = this.opportunity.languages.filter((i) => i.option === 'preferred');
this.languages.required = this.opportunity.languages.filter((i) => i.option === 'required');
this.nationalities.preferred = this.opportunity.nationalities.filter((i) => i.option === 'preferred');
this.nationalities.required = this.opportunity.nationalities.filter((i) => i.option === 'required');








share|improve this question





















  • I am not going to post an answer, because I don't have experience with angular, but why not parse opportunities once by iterating over its keys?
    – Sumurai8
    Apr 29 at 11:14










  • You can definitely answer the question because I'm just asking logic.. which will be written in javascript.
    – Yashwardhan Pauranik
    Apr 29 at 11:24
















up vote
4
down vote

favorite












This my opportunity object which is a part of my angular app.component.ts file. In my template(HTML of this component) I want to loop out different skills backgrounds nationalitiesetc. array using *ngFor*. So I've filtered out these array of objects based on a property option which can have only 2 values either preferred or required. I've implemented such logic inside my TS file using filterByProperty() function as shown below. Please help make this function more simplified and generalized.



opportunity: any = 
"id": 526,
"title": "Testing",
"nationalities": [

"option": "preferred",
"id": 479,
"name": "India",

],
"skills": [

"option": "required",
"id": 1153,
"name": "Adobe Lightroom",
,

"option": "preferred",
"id": 77,
"name": "Python",
,

"option": "preferred",
"id": 78,
"name": "Ajax",
,

"option": "required",
"id": 147,
"name": "3D Max",
,

"option": "preferred",
"id": 175,
"name": "Aircraft Engine Technology",

],
"backgrounds": [

"option": "preferred",
"id": 232,
"name": "Biology",
,

"option": "required",
"id": 249,
"name": "International relations",

],
"languages": [

"option": "required",
"id": 18,
"name": "English",
,

"option": "preferred",
"id": 31,
"name": "Italian",

]



My app.component.ts file



 import Component, OnInit, ViewChild from '@angular/core';

@Component(
selector: 'app-root',
templateUrl: './app.component.html'
)

export class AppComponent implements OnInit

opportunity: any = ; // Object value is shown above
backgrounds: any =
preferred: ,
required:
;
skills: any =
preferred: ,
required:
;
languages: any =
preferred: ,
required:
;
nationalities: any =
preferred: ,
required:
;

ngOnInit()
this.filterByProperty();


filterByProperty()
this.skills.preferred = this.opportunity.skills.filter((i) => i.option === 'preferred');
this.skills.required = this.opportunity.skills.filter((i) => i.option === 'required');
this.backgrounds.preferred = this.opportunity.backgrounds.filter((i) => i.option === 'preferred');
this.backgrounds.required = this.opportunity.backgrounds.filter((i) => i.option === 'required');
this.languages.preferred = this.opportunity.languages.filter((i) => i.option === 'preferred');
this.languages.required = this.opportunity.languages.filter((i) => i.option === 'required');
this.nationalities.preferred = this.opportunity.nationalities.filter((i) => i.option === 'preferred');
this.nationalities.required = this.opportunity.nationalities.filter((i) => i.option === 'required');








share|improve this question





















  • I am not going to post an answer, because I don't have experience with angular, but why not parse opportunities once by iterating over its keys?
    – Sumurai8
    Apr 29 at 11:14










  • You can definitely answer the question because I'm just asking logic.. which will be written in javascript.
    – Yashwardhan Pauranik
    Apr 29 at 11:24












up vote
4
down vote

favorite









up vote
4
down vote

favorite











This my opportunity object which is a part of my angular app.component.ts file. In my template(HTML of this component) I want to loop out different skills backgrounds nationalitiesetc. array using *ngFor*. So I've filtered out these array of objects based on a property option which can have only 2 values either preferred or required. I've implemented such logic inside my TS file using filterByProperty() function as shown below. Please help make this function more simplified and generalized.



opportunity: any = 
"id": 526,
"title": "Testing",
"nationalities": [

"option": "preferred",
"id": 479,
"name": "India",

],
"skills": [

"option": "required",
"id": 1153,
"name": "Adobe Lightroom",
,

"option": "preferred",
"id": 77,
"name": "Python",
,

"option": "preferred",
"id": 78,
"name": "Ajax",
,

"option": "required",
"id": 147,
"name": "3D Max",
,

"option": "preferred",
"id": 175,
"name": "Aircraft Engine Technology",

],
"backgrounds": [

"option": "preferred",
"id": 232,
"name": "Biology",
,

"option": "required",
"id": 249,
"name": "International relations",

],
"languages": [

"option": "required",
"id": 18,
"name": "English",
,

"option": "preferred",
"id": 31,
"name": "Italian",

]



My app.component.ts file



 import Component, OnInit, ViewChild from '@angular/core';

@Component(
selector: 'app-root',
templateUrl: './app.component.html'
)

export class AppComponent implements OnInit

opportunity: any = ; // Object value is shown above
backgrounds: any =
preferred: ,
required:
;
skills: any =
preferred: ,
required:
;
languages: any =
preferred: ,
required:
;
nationalities: any =
preferred: ,
required:
;

ngOnInit()
this.filterByProperty();


filterByProperty()
this.skills.preferred = this.opportunity.skills.filter((i) => i.option === 'preferred');
this.skills.required = this.opportunity.skills.filter((i) => i.option === 'required');
this.backgrounds.preferred = this.opportunity.backgrounds.filter((i) => i.option === 'preferred');
this.backgrounds.required = this.opportunity.backgrounds.filter((i) => i.option === 'required');
this.languages.preferred = this.opportunity.languages.filter((i) => i.option === 'preferred');
this.languages.required = this.opportunity.languages.filter((i) => i.option === 'required');
this.nationalities.preferred = this.opportunity.nationalities.filter((i) => i.option === 'preferred');
this.nationalities.required = this.opportunity.nationalities.filter((i) => i.option === 'required');








share|improve this question













This my opportunity object which is a part of my angular app.component.ts file. In my template(HTML of this component) I want to loop out different skills backgrounds nationalitiesetc. array using *ngFor*. So I've filtered out these array of objects based on a property option which can have only 2 values either preferred or required. I've implemented such logic inside my TS file using filterByProperty() function as shown below. Please help make this function more simplified and generalized.



opportunity: any = 
"id": 526,
"title": "Testing",
"nationalities": [

"option": "preferred",
"id": 479,
"name": "India",

],
"skills": [

"option": "required",
"id": 1153,
"name": "Adobe Lightroom",
,

"option": "preferred",
"id": 77,
"name": "Python",
,

"option": "preferred",
"id": 78,
"name": "Ajax",
,

"option": "required",
"id": 147,
"name": "3D Max",
,

"option": "preferred",
"id": 175,
"name": "Aircraft Engine Technology",

],
"backgrounds": [

"option": "preferred",
"id": 232,
"name": "Biology",
,

"option": "required",
"id": 249,
"name": "International relations",

],
"languages": [

"option": "required",
"id": 18,
"name": "English",
,

"option": "preferred",
"id": 31,
"name": "Italian",

]



My app.component.ts file



 import Component, OnInit, ViewChild from '@angular/core';

@Component(
selector: 'app-root',
templateUrl: './app.component.html'
)

export class AppComponent implements OnInit

opportunity: any = ; // Object value is shown above
backgrounds: any =
preferred: ,
required:
;
skills: any =
preferred: ,
required:
;
languages: any =
preferred: ,
required:
;
nationalities: any =
preferred: ,
required:
;

ngOnInit()
this.filterByProperty();


filterByProperty()
this.skills.preferred = this.opportunity.skills.filter((i) => i.option === 'preferred');
this.skills.required = this.opportunity.skills.filter((i) => i.option === 'required');
this.backgrounds.preferred = this.opportunity.backgrounds.filter((i) => i.option === 'preferred');
this.backgrounds.required = this.opportunity.backgrounds.filter((i) => i.option === 'required');
this.languages.preferred = this.opportunity.languages.filter((i) => i.option === 'preferred');
this.languages.required = this.opportunity.languages.filter((i) => i.option === 'required');
this.nationalities.preferred = this.opportunity.nationalities.filter((i) => i.option === 'preferred');
this.nationalities.required = this.opportunity.nationalities.filter((i) => i.option === 'required');










share|improve this question












share|improve this question




share|improve this question








edited Apr 29 at 16:24









200_success

123k14142399




123k14142399









asked Apr 29 at 10:38









Yashwardhan Pauranik

1234




1234











  • I am not going to post an answer, because I don't have experience with angular, but why not parse opportunities once by iterating over its keys?
    – Sumurai8
    Apr 29 at 11:14










  • You can definitely answer the question because I'm just asking logic.. which will be written in javascript.
    – Yashwardhan Pauranik
    Apr 29 at 11:24
















  • I am not going to post an answer, because I don't have experience with angular, but why not parse opportunities once by iterating over its keys?
    – Sumurai8
    Apr 29 at 11:14










  • You can definitely answer the question because I'm just asking logic.. which will be written in javascript.
    – Yashwardhan Pauranik
    Apr 29 at 11:24















I am not going to post an answer, because I don't have experience with angular, but why not parse opportunities once by iterating over its keys?
– Sumurai8
Apr 29 at 11:14




I am not going to post an answer, because I don't have experience with angular, but why not parse opportunities once by iterating over its keys?
– Sumurai8
Apr 29 at 11:14












You can definitely answer the question because I'm just asking logic.. which will be written in javascript.
– Yashwardhan Pauranik
Apr 29 at 11:24




You can definitely answer the question because I'm just asking logic.. which will be written in javascript.
– Yashwardhan Pauranik
Apr 29 at 11:24










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










The most important piece of advice I can offer is get rid of any. By using any you are making Typescript ignore potential errors in your program. opportunity could be described with the following interfaces:



interface Opportunity 
id: number
title: string
nationalities: Criteria
skills: Criteria
backgrounds: Criteria
languages: Criteria


interface Criteria
option: 'preferred'


Furthermore, the backgrounds, skills, languages, and nationalities properties should be correctly typed. In this case, I'd just add another interface, SeparatedCriteria isn't really the best name, but you can probably come up with a better one as you are more familiar with what each piece of data represents.



interface SeparatedCriteria 
preferred: Criteria
required: Criteria



filterByProperty has a lot of redundancy. At the very least, I would recommend defining isRequired and isPreferred local functions to help cut down on some of the noise.



However, this is still rather noisy especially as the logic is the same for each property - the only thing that changes is the key. With this in mind, we can define an array of keys, ['skills', 'backgrounds', 'languages', 'nationalities'] and assign this[key].preferred and this[key].required.



The trick to making this work correctly is to use both intersection types and index types. It is possible to do this without knowledge of these topics, but the solution will not be type safe as it would be possible to add keys which aren't present in both Opportunity and AppComponent without receiving a compiler error. Here's how I would implement this function. You could now get rid of isRequired and isPreferred as they are only used once, but I believe it makes the logic more clear to leave them as is.



filterByProperty() 
const isPreferred = ( option : Criteria) => option == 'preferred';
const isRequired = ( option : Criteria) => option == 'required';

const propertyKeys: Array<keyof AppComponent & keyof Opportunity>
= ['skills', 'backgrounds', 'languages', 'nationalities'];

for (const key of propertyKeys)
this[key].preferred = this.opportunity[key].filter(isPreferred);
this[key].required = this.opportunity[key].filter(isRequired);







share|improve this answer





















  • Thanks for helping me out. And I'll surely implement the recommended changes.
    – Yashwardhan Pauranik
    Apr 30 at 4:40










  • Can you explain what does that mean in simple english. Array<keyof AppComponent & keyof Opportunity>
    – Yashwardhan Pauranik
    May 17 at 14:14







  • 1




    keyof AppComponent gives an intersection type of all the keys of AppComponent, this is all the property and method names on the class instance. keyof Opportunity gives "id" | "title" | "nationalities" | "skills" | "backgrounds" | "languages", using & to combine them ensures you can only have keys which are contained in *both*Opportunity and AppComponent, then we just define an array of those keys.
    – Gerrit0
    May 18 at 0:08










  • Got it man.. well explained 😀
    – Yashwardhan Pauranik
    May 18 at 7:26










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193196%2ffiltering-objects-according-to-required-and-preferred-attributes%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










The most important piece of advice I can offer is get rid of any. By using any you are making Typescript ignore potential errors in your program. opportunity could be described with the following interfaces:



interface Opportunity 
id: number
title: string
nationalities: Criteria
skills: Criteria
backgrounds: Criteria
languages: Criteria


interface Criteria
option: 'preferred'


Furthermore, the backgrounds, skills, languages, and nationalities properties should be correctly typed. In this case, I'd just add another interface, SeparatedCriteria isn't really the best name, but you can probably come up with a better one as you are more familiar with what each piece of data represents.



interface SeparatedCriteria 
preferred: Criteria
required: Criteria



filterByProperty has a lot of redundancy. At the very least, I would recommend defining isRequired and isPreferred local functions to help cut down on some of the noise.



However, this is still rather noisy especially as the logic is the same for each property - the only thing that changes is the key. With this in mind, we can define an array of keys, ['skills', 'backgrounds', 'languages', 'nationalities'] and assign this[key].preferred and this[key].required.



The trick to making this work correctly is to use both intersection types and index types. It is possible to do this without knowledge of these topics, but the solution will not be type safe as it would be possible to add keys which aren't present in both Opportunity and AppComponent without receiving a compiler error. Here's how I would implement this function. You could now get rid of isRequired and isPreferred as they are only used once, but I believe it makes the logic more clear to leave them as is.



filterByProperty() 
const isPreferred = ( option : Criteria) => option == 'preferred';
const isRequired = ( option : Criteria) => option == 'required';

const propertyKeys: Array<keyof AppComponent & keyof Opportunity>
= ['skills', 'backgrounds', 'languages', 'nationalities'];

for (const key of propertyKeys)
this[key].preferred = this.opportunity[key].filter(isPreferred);
this[key].required = this.opportunity[key].filter(isRequired);







share|improve this answer





















  • Thanks for helping me out. And I'll surely implement the recommended changes.
    – Yashwardhan Pauranik
    Apr 30 at 4:40










  • Can you explain what does that mean in simple english. Array<keyof AppComponent & keyof Opportunity>
    – Yashwardhan Pauranik
    May 17 at 14:14







  • 1




    keyof AppComponent gives an intersection type of all the keys of AppComponent, this is all the property and method names on the class instance. keyof Opportunity gives "id" | "title" | "nationalities" | "skills" | "backgrounds" | "languages", using & to combine them ensures you can only have keys which are contained in *both*Opportunity and AppComponent, then we just define an array of those keys.
    – Gerrit0
    May 18 at 0:08










  • Got it man.. well explained 😀
    – Yashwardhan Pauranik
    May 18 at 7:26














up vote
2
down vote



accepted










The most important piece of advice I can offer is get rid of any. By using any you are making Typescript ignore potential errors in your program. opportunity could be described with the following interfaces:



interface Opportunity 
id: number
title: string
nationalities: Criteria
skills: Criteria
backgrounds: Criteria
languages: Criteria


interface Criteria
option: 'preferred'


Furthermore, the backgrounds, skills, languages, and nationalities properties should be correctly typed. In this case, I'd just add another interface, SeparatedCriteria isn't really the best name, but you can probably come up with a better one as you are more familiar with what each piece of data represents.



interface SeparatedCriteria 
preferred: Criteria
required: Criteria



filterByProperty has a lot of redundancy. At the very least, I would recommend defining isRequired and isPreferred local functions to help cut down on some of the noise.



However, this is still rather noisy especially as the logic is the same for each property - the only thing that changes is the key. With this in mind, we can define an array of keys, ['skills', 'backgrounds', 'languages', 'nationalities'] and assign this[key].preferred and this[key].required.



The trick to making this work correctly is to use both intersection types and index types. It is possible to do this without knowledge of these topics, but the solution will not be type safe as it would be possible to add keys which aren't present in both Opportunity and AppComponent without receiving a compiler error. Here's how I would implement this function. You could now get rid of isRequired and isPreferred as they are only used once, but I believe it makes the logic more clear to leave them as is.



filterByProperty() 
const isPreferred = ( option : Criteria) => option == 'preferred';
const isRequired = ( option : Criteria) => option == 'required';

const propertyKeys: Array<keyof AppComponent & keyof Opportunity>
= ['skills', 'backgrounds', 'languages', 'nationalities'];

for (const key of propertyKeys)
this[key].preferred = this.opportunity[key].filter(isPreferred);
this[key].required = this.opportunity[key].filter(isRequired);







share|improve this answer





















  • Thanks for helping me out. And I'll surely implement the recommended changes.
    – Yashwardhan Pauranik
    Apr 30 at 4:40










  • Can you explain what does that mean in simple english. Array<keyof AppComponent & keyof Opportunity>
    – Yashwardhan Pauranik
    May 17 at 14:14







  • 1




    keyof AppComponent gives an intersection type of all the keys of AppComponent, this is all the property and method names on the class instance. keyof Opportunity gives "id" | "title" | "nationalities" | "skills" | "backgrounds" | "languages", using & to combine them ensures you can only have keys which are contained in *both*Opportunity and AppComponent, then we just define an array of those keys.
    – Gerrit0
    May 18 at 0:08










  • Got it man.. well explained 😀
    – Yashwardhan Pauranik
    May 18 at 7:26












up vote
2
down vote



accepted







up vote
2
down vote



accepted






The most important piece of advice I can offer is get rid of any. By using any you are making Typescript ignore potential errors in your program. opportunity could be described with the following interfaces:



interface Opportunity 
id: number
title: string
nationalities: Criteria
skills: Criteria
backgrounds: Criteria
languages: Criteria


interface Criteria
option: 'preferred'


Furthermore, the backgrounds, skills, languages, and nationalities properties should be correctly typed. In this case, I'd just add another interface, SeparatedCriteria isn't really the best name, but you can probably come up with a better one as you are more familiar with what each piece of data represents.



interface SeparatedCriteria 
preferred: Criteria
required: Criteria



filterByProperty has a lot of redundancy. At the very least, I would recommend defining isRequired and isPreferred local functions to help cut down on some of the noise.



However, this is still rather noisy especially as the logic is the same for each property - the only thing that changes is the key. With this in mind, we can define an array of keys, ['skills', 'backgrounds', 'languages', 'nationalities'] and assign this[key].preferred and this[key].required.



The trick to making this work correctly is to use both intersection types and index types. It is possible to do this without knowledge of these topics, but the solution will not be type safe as it would be possible to add keys which aren't present in both Opportunity and AppComponent without receiving a compiler error. Here's how I would implement this function. You could now get rid of isRequired and isPreferred as they are only used once, but I believe it makes the logic more clear to leave them as is.



filterByProperty() 
const isPreferred = ( option : Criteria) => option == 'preferred';
const isRequired = ( option : Criteria) => option == 'required';

const propertyKeys: Array<keyof AppComponent & keyof Opportunity>
= ['skills', 'backgrounds', 'languages', 'nationalities'];

for (const key of propertyKeys)
this[key].preferred = this.opportunity[key].filter(isPreferred);
this[key].required = this.opportunity[key].filter(isRequired);







share|improve this answer













The most important piece of advice I can offer is get rid of any. By using any you are making Typescript ignore potential errors in your program. opportunity could be described with the following interfaces:



interface Opportunity 
id: number
title: string
nationalities: Criteria
skills: Criteria
backgrounds: Criteria
languages: Criteria


interface Criteria
option: 'preferred'


Furthermore, the backgrounds, skills, languages, and nationalities properties should be correctly typed. In this case, I'd just add another interface, SeparatedCriteria isn't really the best name, but you can probably come up with a better one as you are more familiar with what each piece of data represents.



interface SeparatedCriteria 
preferred: Criteria
required: Criteria



filterByProperty has a lot of redundancy. At the very least, I would recommend defining isRequired and isPreferred local functions to help cut down on some of the noise.



However, this is still rather noisy especially as the logic is the same for each property - the only thing that changes is the key. With this in mind, we can define an array of keys, ['skills', 'backgrounds', 'languages', 'nationalities'] and assign this[key].preferred and this[key].required.



The trick to making this work correctly is to use both intersection types and index types. It is possible to do this without knowledge of these topics, but the solution will not be type safe as it would be possible to add keys which aren't present in both Opportunity and AppComponent without receiving a compiler error. Here's how I would implement this function. You could now get rid of isRequired and isPreferred as they are only used once, but I believe it makes the logic more clear to leave them as is.



filterByProperty() 
const isPreferred = ( option : Criteria) => option == 'preferred';
const isRequired = ( option : Criteria) => option == 'required';

const propertyKeys: Array<keyof AppComponent & keyof Opportunity>
= ['skills', 'backgrounds', 'languages', 'nationalities'];

for (const key of propertyKeys)
this[key].preferred = this.opportunity[key].filter(isPreferred);
this[key].required = this.opportunity[key].filter(isRequired);








share|improve this answer













share|improve this answer



share|improve this answer











answered Apr 29 at 18:41









Gerrit0

2,6501518




2,6501518











  • Thanks for helping me out. And I'll surely implement the recommended changes.
    – Yashwardhan Pauranik
    Apr 30 at 4:40










  • Can you explain what does that mean in simple english. Array<keyof AppComponent & keyof Opportunity>
    – Yashwardhan Pauranik
    May 17 at 14:14







  • 1




    keyof AppComponent gives an intersection type of all the keys of AppComponent, this is all the property and method names on the class instance. keyof Opportunity gives "id" | "title" | "nationalities" | "skills" | "backgrounds" | "languages", using & to combine them ensures you can only have keys which are contained in *both*Opportunity and AppComponent, then we just define an array of those keys.
    – Gerrit0
    May 18 at 0:08










  • Got it man.. well explained 😀
    – Yashwardhan Pauranik
    May 18 at 7:26
















  • Thanks for helping me out. And I'll surely implement the recommended changes.
    – Yashwardhan Pauranik
    Apr 30 at 4:40










  • Can you explain what does that mean in simple english. Array<keyof AppComponent & keyof Opportunity>
    – Yashwardhan Pauranik
    May 17 at 14:14







  • 1




    keyof AppComponent gives an intersection type of all the keys of AppComponent, this is all the property and method names on the class instance. keyof Opportunity gives "id" | "title" | "nationalities" | "skills" | "backgrounds" | "languages", using & to combine them ensures you can only have keys which are contained in *both*Opportunity and AppComponent, then we just define an array of those keys.
    – Gerrit0
    May 18 at 0:08










  • Got it man.. well explained 😀
    – Yashwardhan Pauranik
    May 18 at 7:26















Thanks for helping me out. And I'll surely implement the recommended changes.
– Yashwardhan Pauranik
Apr 30 at 4:40




Thanks for helping me out. And I'll surely implement the recommended changes.
– Yashwardhan Pauranik
Apr 30 at 4:40












Can you explain what does that mean in simple english. Array<keyof AppComponent & keyof Opportunity>
– Yashwardhan Pauranik
May 17 at 14:14





Can you explain what does that mean in simple english. Array<keyof AppComponent & keyof Opportunity>
– Yashwardhan Pauranik
May 17 at 14:14





1




1




keyof AppComponent gives an intersection type of all the keys of AppComponent, this is all the property and method names on the class instance. keyof Opportunity gives "id" | "title" | "nationalities" | "skills" | "backgrounds" | "languages", using & to combine them ensures you can only have keys which are contained in *both*Opportunity and AppComponent, then we just define an array of those keys.
– Gerrit0
May 18 at 0:08




keyof AppComponent gives an intersection type of all the keys of AppComponent, this is all the property and method names on the class instance. keyof Opportunity gives "id" | "title" | "nationalities" | "skills" | "backgrounds" | "languages", using & to combine them ensures you can only have keys which are contained in *both*Opportunity and AppComponent, then we just define an array of those keys.
– Gerrit0
May 18 at 0:08












Got it man.. well explained 😀
– Yashwardhan Pauranik
May 18 at 7:26




Got it man.. well explained 😀
– Yashwardhan Pauranik
May 18 at 7:26












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f193196%2ffiltering-objects-according-to-required-and-preferred-attributes%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation