If I manually create an array with
array = ["2","1","3"]
array.sort will return a sorted version of the array.
But if I create an array by using
array2 = ["213".split(//)]
or
array2 = []
array2 << "213".split(//)
array2.sort will return the unsorted array.
Why doesn’t this work? Are the arrays created like that somehow different, and if yes, how?
You define array2 as [“213”.split(//)]. This puts an array ([“2″,”1″,”3”]) inside an array. The output is:
When you try and sort that, it sorts the “bigger” array: the one with one element!
This works, though: