My task involves manipulating an array through two methods in sequence:
- Filter the array
- Then, sort it
The filter method I am using is as follows:
filterArray(list){
return list.filter(item => !this.myCondition(item));
}
The sort method I am using is as follows:
sortArray(list) {
return list.sort((a, b) => new Date(b.beginDate).getTime() - new Date(a.beginDate).getTime());
}
I want to ensure that the array is completely filtered before sorting it.
I have attempted the following:
myData = myData.filterArray(myData).sortArray(myData);
However, I am uncertain if this is the most efficient approach. (Note: I prefer to keep the sorting and filtering methods separate)
What are the best ways to achieve this?