Jump to content

Wikipedia:File article draft

From Wikipedia, the free encyclopedia

How the JavaScript's array function 'sort(function)' works:

1. If the function parameter isn't provided, then:

 1-1. If the items are all strings:
   1-1-1. It sorts the items in alphabetical order. It does modify the original array.
 1-2. If the items are all numbers:
   1-2-1. It sorts the items (whether they are less than next numbers as in an order) / sorts the numbers in ascending order.

2. If the function parameter is provided, then:

 2-1. If the items are all numbers:
   2-1-1. When the function returns a negative number, the item is put at the first item of the list, or it will be put next to the number less than the number that is added.

3. Else, return the original array.

(Written by Theknowledgeperson.)

PS: I need help renaming the title.