A11yWatch/a11ywatch-core

View on GitHub
src/core/utils/filters/limit-issue.ts

Summary

Maintainability
A
1 hr
Test Coverage
// limit the issue records to 1/4th todo: pre-allocate
// @return Issue['issues'][]
export const limitIssue = (issues: any[]) => {
  if (!issues || (issues && Array.isArray(issues) && !issues.length)) {
    return [];
  }

  const half = Math.ceil(issues.length / 2);

  const tlist = issues.slice(0, half);
  const blist = issues.slice(half);

  const top = tlist.slice(
    tlist.length - Math.max(Math.round(tlist.length / 4), 2)
  );

  const bottom = blist.slice(
    blist.length - Math.max(Math.round(blist.length / 4), 2)
  );

  return [...top, ...bottom];
};