To take the quizzes, you must log in.

*Username:***student***Password:***Formulas.1**You can view this site in

the language of your choice.

- sort()
### sort()

# sort()

**Function****Examples****Result****Description**sort(X) sort(["B","C","A"]) ["A","B","C"] Returns the sorted list of X in ascending order. sort(X,Y) sort(["B","C","A"],[0,2,1]) ["B","A","C"] Sorts the list X,Y together by sorting Y in ascending order and returns the sorted list X. (??) ### Example

**Function****Returns****Comments**sort([1,4,3,9,6,0,2,7,8,5]) ⇒ [0,1,2,3,4,5,6,7,8,9] sort(["d","g","b","c","e","j","f","h","a","i"]) ⇒ ["a","b","c","d","e","f,"g","h","i","j"] sort(["G","D","A","F","B","I","C","E","H","J"]) ⇒ ["A","B","C","D","E","F,"G","H","I","J"] sort(["a","d","C","E","c","D","e","b","B","A"]) ⇒ ["A","B","C","D","E","a","b","c","d","e"] sort(["c","A","2","C","B","3","1","a","4","b"]) ⇒ ["A","B","C","a","b","c","1","2","3","4"] Numbers should come first. ## Unexpected results and bugs

sort(["4","3","A","a","B","2","1","b","c","C"]) returns ["A","B","C","a","b","c","1","2","3","4"], i.e. the letters come before the numbers.

The sort() functions in PHP and JavaScript do not behave like this. They would return ["1","2","3","4","A","B","C","a","b","c"], i.e. the numbers come first.sort(["B","C","A","B"]) returns ["A","B","C"], i.e. when two (or more) members are equal, they are merged into one member in the sorted arreay.

The sort() functions in PHP and JavaScript do not behave like this. They would return ["A","B","B","C"].sort(["B","3","1","0","A","C","c","b","2","a"]) returns ["B","3","1","0","A","C","c","b","2","a"], i.e. the "0" element seems to interfere with the sorting.

The sort() functions in PHP and JavaScript would return ["0","1","2","3","A","B","C","a","b","c"].## References