Instead of manually comparing and filtering out the elements you can use the filter function in javascript to remove all the falsy values from the array.
The syntax of the function is as follows
arr.filter(Boolean)
Boolean is a built-in JavaScript function that coerces its argument to a boolean value. It returns false for falsy values (undefined , null , 0 , NaN , "" , false ), and true for truthy values.
Any element that is falsy (according to the Boolean conversion rules) will be excluded from the resulting array because Boolean(falsyValue) returns false .
I see that thank you so much! but I was trying to pass the lesson with various methods. I was wondering what went wrong here since I dont want to have any concepts left foggy.