Minimum Cost to Move Chips to The Same Position LeetCode solution in JavaScript
1var minCostToMoveChips = function (position) {2const hashMap = new Map();3let odd = 0,4even = 0;5for (const chip of position) {6if (hashMap.has(chip)) hashMap.set(chip, hashMap.get(chip) + 1);7else hashMap.set(chip, 1);8}9for (const [key, value] of hashMap) {10if (key % 2 === 0) even += value;11else odd += value;12}13return Math.min(odd, even);14};