{"size": 1689, "ext": "js", "max_stars_repo_path": "src/count-cats.js", "max_stars_repo_name": "madkorney/basic-js", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/count-cats.js", "max_issues_repo_name": "madkorney/basic-js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/count-cats.js", "max_forks_repo_name": "madkorney/basic-js", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.6315789474, "max_line_length": 131, "alphanum_fraction": 0.5050325636}
const { NotImplementedError } = require('../extensions/index.js');

/**
 * Given matrix where you have to find cats by ears "^^"
 *
 * @param {Array<Array>} matrix 
 * @return {Number} count of cats found
 *
 * @example
 * countCats([
 *  [0, 1, '^^'],
 *  [0, '^^', 2],
 *  ['^^', 1, 2]
 * ]) => 3`
 *
 */
function countCats(backyard) {
  //throw new NotImplementedError('Not implemented');
  // remove line with error and write your code here
  let catsCount = 0;
  const cat = '^^';
  let backyardXFence = backyard.length;
  let backyardYFence = (Array.isArray(backyard[0])) ? backyard[0].length : 0; // no validation for marix with defferent rows length

  if (backyardXFence == 0 || backyardYFence == 0) {
    return catsCount;
  }

  catsCount = backyard.reduce((catsCountX, row) => {
    return catsCountX + row.reduce((catsCountY, item) => {
      if (item == cat) {catsCountY++};
      return catsCountY;
    } , 0)
  }, 0);
  return catsCount;
}

module.exports = {
  countCats
};

// console.log(countCats([
//   ["^^", ".", null, 0, false, "", NaN, "^^", 2, true, "dasdas", 1],
//   [2, null, 0, 1, ".", "dasdas", true, NaN, "", false, "^^", "^^"],
//   [false, ".", 1, 0, "^^", null, "", 2, "dasdas", "^^", NaN, true],
//   [".", false, 1, null, NaN, 2, 0, "dasdas", true, "^^", "", "^^"],
//   [false, ".", 1, 0, "^^", true, null, "^^", "", NaN, 2, "dasdas"],
//   [false, NaN, 1, 0, ".", "^^", null, true, "dasdas", "^^", 2, ""],
//   [null, 1, NaN, true, ".", "^^", "^^", 2, "", false, "dasdas", 0],
//   [null, NaN, "", false, ".", 1, 0, "^^", "dasdas", true, 2, "^^"],
// ]));
// console.log(
// countCats([[0, 1, '^^'],
//   [0, '^^', 2],
//   ['^^', 1, 2]
//   ])
// );