I have a string array with values in the format "dd MMMM":
var myArray = ['13 October','13 November','13 May','13 August','13 November','13 February','13 May',
'13 August','13 November','13 February','13 May','13 August','13 November','13 February','13 May',
'13 August','13 November','13 February','13 May','13 August','13 November','14 November']
I need remove duplicates whilst maintaining date order.
I started off with:
function myFunction(array) {
array.sort();
newArray = [array[0]];
for (i = 1; i < array.length; i++) {
if (array[i] != array[i-1]) {
newArray.push(array[i]);
}
}
return newArray
};
That results in an array which is no longer in date order, so as a hack I then looped through the string array, appended " 9999" to the end of each value and then parsed it as a date. I sorted the new array, before formatting each value as "dd MMMM" to give me the final output:
['13 February','13 May','13 August','13 October','13 November','14 November']
Whilst it works, it is some terrible code. Any advice on how to remove duplicates from the initial array and sort it by strings which have "dd MMMM" and no "yyyy"?
/Edit: Apologies, I should have mentioned that this JavaScript is being in a third party application and it doesn't support many of the common methods - Set, indexOf, =>, sortBy etc.
