can you convert this code dnippet to challenge type code problems like leetcode…
- User
can you convert this code dnippet to challenge type code problems like leetcode problems. Problem should be real world problem and should be abstract: `"use strict"; const { _, compact } = require("underscore");
(function () { console.log(_.compact([0, 1, false, 2, '', 3])); })();`
- Assistant
Problem Statement:
In a robot path planning algorithm, you are given a list representing sensor readings regarding obstacles around the robot. Each element can be a non-zero number (indicating the distance to the obstacle) or it can be a falsey value (
0,false,'', etc.) which indicates no obstacle detected or faulty readings that need to be discarded.The robot software should be able to filter out the unreliable readings before processing the data for path calculation.
You need to implement a function
filterSensorReadingswhich takes an array of readings and returns a new array with all falsey values removed, preserving only the non-zero distances.Function Signature: