Filter Without Truthiness Bugs
Filter Without Truthiness Bugs
filter predicates often look like simple yes-or-no checks, but the exact condition matters. A truthiness check can accidentally remove valid data such as 0, because JavaScript treats zero as falsy.
Sensor and analytics data frequently contain zero as a meaningful value. A correct predicate should check the type and validity of the reading, not whether the value feels truthy. The returned array should keep the original reading records in their original order.
Your task: Complete validReadings so it keeps readings whose value is a number and not NaN. Keep readings with a value of 0, and do not mutate the source records.
Free with a JS Exercises account
Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.
By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.
Filter Without Truthiness Bugs
filter predicates often look like simple yes-or-no checks, but the exact condition matters. A truthiness check can accidentally remove valid data such as 0, because JavaScript treats zero as falsy.
Sensor and analytics data frequently contain zero as a meaningful value. A correct predicate should check the type and validity of the reading, not whether the value feels truthy. The returned array should keep the original reading records in their original order.
Your task: Complete validReadings so it keeps readings whose value is a number and not NaN. Keep readings with a value of 0, and do not mutate the source records.