All files / src/lib/tools middle.js

100% Statements 2/2
100% Branches 2/2
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12                4x 4x    
/**
 * if total number of images are not even, then one canvas is
 * not required. In this case place this in the middle of the layout
 * @module
 * @param {array} matrix col,row counts of the game.
 * @return {integer} index of the mid-element otherwise -1
 */
export function oddMiddle(matrix) {
  const [col, row] = matrix;
  return (col * row) % 2 === 1 ? (col * row - 1) / 2 : -1;
}