I have implemented reusable sorting function,sorting by number and text are working fine,But it fails for sort by date.
orderBy(array: Array<any>, fieldName: string, direction: string) {
return array.sort((a, b) => {
let objectA: number|string = '';
let objectB: number|string = '';
[objectA, objectB] = [a[fieldName], b[fieldName]];
let valueA = isNaN(+objectA) ? objectA.toString().toUpperCase() : +objectA;
let valueB = isNaN(+objectB) ? objectB.toString().toUpperCase() : +objectB;
return (valueA < valueB ? -1 : 1) * (direction == 'asc' ? 1 : -1);
});
}
how to sort by date, text numbers and special char.