Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
303 B
2
Indexable
Never
function sort(arr:any, key:string, direction:string) {
    const factor = direction === 'ASC' ? 1 : -1;
    return [...arr].sort((a, b) => {
      if (a[key] === 'unknown') return 1;
      if (b[key] === 'unknown') return -1;
      return (Number(a[key]) > Number(b[key]) ? 1 : -1) * factor;
    });
  }