I needed a way to eliminate empty elements and Carriage Returns from the end of an array. Here's an example of what my array looks like:
Input arr:
['', 'Apple', '', 'Banana', '', 'Guava', '', '', '', '\r']
Desired Output:
['', 'Apple', '', 'Banana', '', 'Guava']
Explanation of trailing empty elements : There are no valid elements following the last one ('Guava' in this instance).