Ok, so you decided to turn your string into an array of strings. So if we think about the data type that you are using, it might look something like this:
[string, string, string, string]
Then you decided to sort that array, so let’s have a look at the documentation for the
compare function in the array’s
If compareFunction is supplied, the array elements are sorted according to the return value of the compare function. If a and b are two elements being compared, then:
If compareFunction(a, b) is less than 0, sort a to an index lower than b, i.e. a comes first.
If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, but sorted with respect to all different elements. Note: the ECMAscript standard does not guarantee this behaviour, and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.
If compareFunction(a, b) is greater than 0, sort b to an index lower than a, i.e. b comes first.
compareFunction(a, b) must always return the same value when given a specific pair of elements a and b as its two arguments. If inconsistent results are returned then the sort order is undefined.
The important part here is that
b are two elements from the array that are being compared.
So, the first thing to ask since
b are both strings (i.e., words), what does it mean to say
(I hope I am not being too obtuse. I don’t want to give away the answer. So please continue to ask questions if my hints are not enough!)