I have an array something like this:
[["a", nil, nil, nil], ["b", nil, "c", nil], [nil, nil, nil, nil]]
I want to remove all trailing nil values from array in ruby.
I tried arr.map {|x| x.pop until x.last} but the problem with this approach is that when all the value of arrays are nil like in 3rd array in given array, the loop stucks.
Because of the until x.last condition, If all the values are nil then the map function should return me an empty array?
What should be the conditions for this.
The output should be
[['a'],['b','nil','c'],[]]
Remember I just want to remove trailing nil values not in between.
nilvalues really be converted to'nil'strings?