Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COGreat thanks Gion that works perfectly. To be honest the sort function completely baffles me. I'm passing 'a' and 'b' as parameters to the 'dmyOrdA' function but I can't see what relationship this has to my 'times' array. If you had time it would be great if you could explain this. Thanks.
      singulars
    2. CO@Stephen Young: When you sort an array in javascript, you need to provide a way of comparison between two of the array's elements. This way, you pass as a parameter to the sort method a function that takes 2 elements of your array and decides which one will be `lower` and which one will be `greater`.If the first element is `grater` than the other, the function will return `1`.If it is lower than the other, it will return `-1`, and if they're equal, it returns `0`. You can picture the function as a question: is the first element bigger than the second?Answer:`1`-yes,`-1`-no,`0`-inconclusive
      singulars
    3. CO@gion_13 I think I'm beginning to understand this. Just two questions: (1) You say "you pass as a parameter to the sort method a function that takes 2 elements of your array" but how does the sort method know how to sort _all_ the elements in the array? (2) I don't understand the `return` aspect of the function. If you take out the `else if` part and change `if (a > b) return 1` to `if (a > b) return -1` it will still sort by ascending order. However, if you leave out the `(a > b)` statement and just have `if (a < b) return -1` it will not sort by descending order but `return 1` will. Why?
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload