Type Predicates and Assertion Functions 6 exercises
Problem

Filtering with Type Predicates

In this exercise we have a set of values which sometimes have strings and sometimes have undefined.

These filteredValues are filtering out the undefined by checking for truthiness.


export const values = ["a", "b", undefined, "c", undefined];
const filteredValues = values.filte

Loading exercise

Transcript

0:00 In this exercise, we have a set of values which sometimes have strings and sometimes have undefined. These filtered values are basically, we're filtering out the undefined. What we're doing here is we're just checking for truthiness.

0:13 We end up with A, B, and C in the filtered values. This test is going to pass. This is not passing down here because we're expecting them to be an array of strings. Actually, even though we filter them out, they're still expressed as string or undefined in the array.

0:30 What I want you to do is find a piece of syntax which fits inside here that will allow us to basically express that this filter is filtering out the undefined values. The way I want you to do that is with a type predicate. You'll have some links in the section resources. Good luck!