Minimum Domino Rotations For Equal Row LeetCode solution in JavaScript
1/**2* @param {number[]} tops3* @param {number[]} bottoms4* @return {number}5*/6var minDominoRotations = function (tops, bottoms) {7const swaps = Math.min(8minimum(tops[0], tops, bottoms),9minimum(tops[0], bottoms, tops),10minimum(bottoms[0], tops, bottoms),11minimum(bottoms[0], bottoms, tops)12);1314return swaps === Infinity ? -1 : swaps;1516function minimum(target, x, y, count = 0) {17for (let i = 0; i < x.length; i++) {18if (target !== x[i]) {19if (target !== y[i]) return Infinity;20count++;21}22}23return count;24}25};