Timeline for Filter an object array based on certain conditions
Current License: CC BY-SA 4.0
19 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 11, 2022 at 3:00 | history | tweeted | twitter.com/StackCodeReview/status/1480736433354723336 | ||
Jan 7, 2022 at 7:29 | vote | accept | user3378165 | ||
Jan 6, 2022 at 23:57 | answer | added | radarbob | timeline score: 2 | |
Jan 6, 2022 at 20:41 | review | Close votes | |||
Jan 8, 2022 at 14:43 | |||||
Jan 6, 2022 at 20:38 | comment | added | user3378165 | Thanks, I edited the question. | |
Jan 6, 2022 at 20:36 | history | edited | user3378165 | CC BY-SA 4.0 |
added 1 character in body
|
Jan 6, 2022 at 20:29 | comment | added | radarbob |
That contact object is not valid javascript. Is it a snippet from a JSON object? Are you unpacking the JSON to an array of proper JS objects? There is not enough context (code ) to tell how or if this works.
|
|
Jan 6, 2022 at 20:06 | comment | added | user3378165 | Thanks for the guidance, I have edited the question, I hope now it's clearer. | |
Jan 6, 2022 at 20:05 | history | edited | user3378165 | CC BY-SA 4.0 |
added 75 characters in body
|
Jan 6, 2022 at 19:46 | comment | added | radarbob | Your comment reply I want to remove all the other types Again, "remove" means "delete". I think I know you do not mean that. And also that there is no such thing as "type" anywhere in the code itself; the description and the actual code conflict. I'm being a pedantic pain just to show how precision, terminology, etc. is so important to readers trying to evaluate correctness and suggest changes. | |
Jan 6, 2022 at 19:44 | comment | added | user3378165 |
Yes, correct, I referred to contact.relationship
|
|
Jan 6, 2022 at 19:34 | comment | added | radarbob |
There is no contact.type property. I assume you mean object.relationship to be the type?
|
|
Jan 6, 2022 at 11:06 | comment | added | user3378165 |
@radarbob the contacts list can contain contacts of 4 different types, A , B , C and D . If there are contacts of type A I want to remove all the other types and only get the ones with type A , If there are no type A contacts, I only want to get the type B contacts. If no type A and no type B then the list should return empty. I have edited my question and added the contact object.
|
|
Jan 6, 2022 at 11:05 | history | edited | user3378165 | CC BY-SA 4.0 |
added 152 characters in body
|
Jan 5, 2022 at 23:11 | comment | added | radarbob |
Show the contact definition in the code. Without knowing that and how it one is created an answer is guesswork. The chaining operator ?. implies a contact contains other objects that may or may not be contact object(s). Then defaulting the property to an empty string implies these properties may or may not be initialized upon creation.
|
|
Jan 5, 2022 at 22:32 | comment | added | radarbob |
Please clarify: If contactNames contains any "type A" contacts then return all the "type B" contacts; then if there are no "type A" contacts then return nothing / an empty set? Also, "... should only leave contacts of type B" - "leave" implies to delete all contacts except "typeB" from contactNames .
|
|
Jan 5, 2022 at 20:54 | answer | added | alexanderbird | timeline score: 4 | |
Jan 5, 2022 at 19:56 | history | edited | user3378165 | CC BY-SA 4.0 |
added 16 characters in body
|
Jan 5, 2022 at 16:06 | history | asked | user3378165 | CC BY-SA 4.0 |