function orderBy(array, fields, directions) {
  const sorted = [...array];
  sorted.sort((a, b) => {
    for (let i = 0; i < fields.length; i++) {
      const field = fields[i];
      const direction = directions[i];
      if (a[field] < b[field]) {
        return direction === "asc" ? -1 : 1;
      } else if (a[field] > b[field]) {
        return direction === "asc" ? 1 : -1;
      }
    }
    return 0;
  });
  return sorted;
}

export { orderBy };
