Skip to content

filter map objects using javascript #621

Answered by mdazfar2
NitishKumar525 asked this question in Q&A
Discussion options

You must be logged in to vote

@NitishKumar525 Your filtering function looks mostly correct, but there're some issues.

  1. you should add the missing return some() callback.
  2. you should add a null-safe check for appErrorSummaryKeyword.

Here's updated code.

const searchException = () => { return new Map( Array.from(input).filter(([key, value]) => { const matchInvocations = value.invocations.some((invocation) => invocation?.radar?.includes(filterFailureInput) );

  const matchErrorSummary =
    value?.testErrorSummary?.toLowerCase().includes(filterFailureInput.toLowerCase()) ||
    value?.appErrorSummaryKeyword?.toLowerCase()?.includes(filterFailureInput.toLowerCase());

  return matchInvocations || matchErrorSummary;
})

); };

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by NitishKumar525
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants