{"size": 726, "ext": "js", "max_stars_repo_path": "app/common/matrix-parser.service.js", "max_stars_repo_name": "c-bandy/open-hue", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/common/matrix-parser.service.js", "max_issues_repo_name": "c-bandy/open-hue", "max_issues_repo_issues_event_min_datetime": "2018-11-03T01:02:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-03T02:03:30.000Z", "max_forks_repo_path": "app/common/matrix-parser.service.js", "max_forks_repo_name": "c-bandy/open-hue", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 20.7428571429, "max_line_length": 56, "alphanum_fraction": 0.4724517906}
angular.module('app')
  .factory('matrixParserService', ($log) => {
    const toObject = (element) => ({
      isLocked: element === 'x',
    });

    const expand = (acc, curr) => {
      const quantifier = Number(acc[acc.length - 1]);

      if (isNaN(quantifier)) {
        return acc + curr;
      }

      return acc.slice(0, -1) + curr.repeat(quantifier);
    };

    function parse(matrix) {
      const mapped = matrix.split(/\n/)
        .filter((element) => element.length > 0)
        .map((row) => {
          return row.trim()
            .split('')
            .reduce(expand, '')
            .split('')
            .map(toObject);
        });

      return mapped;
    }

    return {
      parse,
    };
  });
