J
Josselin
I am trying to delete an element from an array if it exists and count
the number of item afterwards
I wrote
anArray = [1,2,3,4,5,6,7,8,9]
anArray.size
=> 9
anArray.map {|e| e if e != 4}.compact
=> [1, 2, 3, 5, 6, 7, 8, 9]
anArray.map {|e| e if e != 4}.compact.size
=> 8
is ther a better way to do it... it it's enough ? (learning always how
to write better code..)
thanks
joss
the number of item afterwards
I wrote
anArray = [1,2,3,4,5,6,7,8,9]
anArray.size
=> 9
anArray.map {|e| e if e != 4}.compact
=> [1, 2, 3, 5, 6, 7, 8, 9]
anArray.map {|e| e if e != 4}.compact.size
=> 8
is ther a better way to do it... it it's enough ? (learning always how
to write better code..)
thanks
joss