ruby - Delete leading nils from Array -


i have array so:

[nil, nil, nil, 2, 4, 6, 1, nil, nil, 3, 4, 6] 

what need nice way remove leading nils in place (so compact! bad), , number of nils removed (so drop_while bad).

probably not idea, if insist on one-liner:

arr.instance_eval { shift(index { |element| !element.nil? } || size) }.count 


edit: anyone's future reference, better looking version agreed upon:

arr.shift(arr.index(&:itself) || arr.size).count 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -