Manipulating an array of integers is returning unexpected results with ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin13] :
a = [1, 126, 158, 201, 102]
=> [1, 126, 158, 201, 102]
b = 102
=> 102
a.delete(b)
=> 102
many slight variations of syntax always lead to the same result.
is the syntax mistaken, could there be some higher command that negates this command or worse, is some corruption issue at hand? How can this be ascerted?
>Solution :
From the Array#delete docs:
When no block is given, removes from self each element ele such that
ele == obj; returns the last deleted element…
In your case b is equal to 102, hence it prints its value after defining the variable. Then a.delete(b) corroborates that there’s an element in a equals to b so it deletes it and returns the value of b.