-3

arr.sort((a, b) => a < b ? 1 : a > b ? -1 : 0); 'I don't understand what's meaning double dot between 1 and a ?

  • 1
    [Ternary operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) I recommend using also `(` and `)` – IT goldman Jul 30 '22 at 11:07
  • You would be far more able to find the appropriate information if you knew the names of the symbols you're looking at - that "double dot" is a _colon_. You can also use https://stackoverflow.com/q/9549780/3001761. – jonrsharpe Jul 30 '22 at 11:11
  • This has nothing to do with `python-3.x` so why the tag? – Andreas Jul 30 '22 at 11:12

1 Answers1

0

Expresion a < b ? 1 : a > b ? -1 : 0 is equivalent to:

if (a < b) {
    return 1
} else {
    if (a > b) {
        return -1
    } else {
        return 0
    }
}

The colon : essentialy means else in ternary operator

condition ? return this if the condition is true : return if the condition is false

voyt97
  • 176
  • 10