Count of Matches in Tournament LeetCode solution in JavaScript
1/**2* @param {number} n3* @return {number}4*/5var numberOfMatches = function (n) {6let matches = 0,7current = n;8while (current > 1) {9if (current % 2 === 0) {10matches += current / 2;11current = current / 2;12} else {13matches += (current - 1) / 2;14current = (current - 1) / 2 + 1;15}16}17return matches;18};