ES6 JavaScript O(N^2) beats 98% with explanation
Every team is consist of 3 members, say Left, Middle and Right. (Left = rating[i], Middle = rating[j],  Right = rating[k])\n\nIf the value is in ascending order
Every team is consist of 3 members, say **Left**, **Middle** and **Right**. (Left = rating[i], Middle = rating[j],  Right = rating[k])\n\nIf the value is in ascending order: **Left** < **Middle** < **Right**\nIf the value is in descending order: **Left** > **Middle** > **Right**\n\nBy checking the posible **Left** member count and **Right** member count, we can then get the total composition count by multiplying them. \n(Note that we need to calculate **asc**ending and **desc**ending count separately.)\n\n```\nconst numTeams = rating => {\n  let ans = 0;\n\n  // \'i\' is the index of Middle\n  for (let i = 1; i < rating.length - 1; i++) {\n    let descLeft = 0;\n    let descRight = 0;\n\tlet ascLeft = 0;\n\tlet ascRight = 0;\n\n    // Check for Left\n    for (let j = 0; j < i; j++) {\n      if (rating[j] > rating[i]) descLeft++;\n      if (rating[j] < rating[i]) ascLeft++;\n    }\n\n    // Check for Right\n    for (let j = i + 1; j < rating.length; j++) {\n      if (rating[j] < rating[i]) descRight++;\n      if (rating[j] > rating[i]) ascRight++;\n    }\n\n    ans += descLeft * descRight + ascLeft * ascRight;\n  }\n\n  return ans;\n};\n```
['JavaScript']