It is impossible to do this perfectly! Consider two strings that consist of the same digits and different trailing whitespace. As numbers, they are equal. As strings, they are not. There is no way to tell (from the data alone) which is intended. Coercing everything to strings suppresses the "nastygrams" and is correct for all but a few special cases.
Bill
Comment on Re: Filtering array of strings and numbers
Say rather that it may take more effort than we would like (but it shouldn't be impossible) to fully describe what is meant by "perfectly" for a given task relating to a given set of data.