I found this simple problem in javascript
, when making a number sort
by one array
, it did not order them correctly from smallest to largest:
var arrayStrings = ['Banana', 'World', 'Apple', 'Chocolate']
var arrayNumbers = [10, 8, 9, 5, 3, 78, 23]
console.log(arrayStrings.sort()) // Lo ordena bien
console.log(arrayNumbers.sort()) // Lo ordena mal
I was able to solve it this way:
It can also be done implicitly by doing one
prototype
of the following:I think that programmers in general complicate your life in a bad way. The thing is much simpler.
It is the same method only that you make the comparison of which is less and changes