3101. Count Alternating Subarrays
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\nvar countAlternatingSubarrays = function (a) {\n\tconst n = a.length;\n\tlet alternatingSubarrayCount = 1;\n\tlet sum = alternatingSubarrayCount;\n\tfor (let i = 1; i < n; i++) {\n\t\tif (a[i - 1] !== a[i]) {\n\t\t\talternatingSubarrayCount += 1;\n\t\t} else {\n\t\t\talternatingSubarrayCount = 1;\n\t\t}\n\t\tsum += alternatingSubarrayCount;\n\t}\n\treturn sum;\n};\n\n```
['JavaScript']