export function userMatchesFilter(user, searchFilter) {
  const searchTerms = searchFilter.split(/\s+/).map(val => val.toLowerCase());
  const fullName = user.full_name.toLowerCase();
  const username = user.username.toLowerCase();
  return searchTerms.every(term => fullName.includes(term) || username.includes(term));
}

export function filterAndSortUsers(users, pred, sortByKey = 'username') {
  return users.filter(pred).sort(
    // use 'search' option to ignore case rather than use locale defaults
    (a, b) => {
      return String(a[sortByKey]).localeCompare(String(b[sortByKey]), 'default', {
        usage: 'search',
      });
    }
  );
}

export function userMatchesFilter(user, searchFilter) {
  const searchTerms = searchFilter.split(/\s+/).map(val => val.toLowerCase());
  const fullName = user.full_name.toLowerCase();
  const username = user.username.toLowerCase();
  return searchTerms.every(term => fullName.includes(term) || username.includes(term));
}

export function filterAndSortUsers(users, pred = () => true, sortByKey = 'full_name') {
  return users.filter(pred).sort(
    // use 'search' option to ignore case rather than use locale defaults
    (a, b) => {
      return String(a[sortByKey]).localeCompare(String(b[sortByKey]), 'default', {
        usage: 'search',
      });
    }
  );
}

Sort users by their fullname rather than username when displayed in a table.
Sort users by their fullname rather than username when displayed in a table.

Change default user sort field to full_name
