Sort months ( with strings ) algorithm

前端 未结 10 1153
深忆病人
深忆病人 2021-01-18 03:42

I have this months array:

[\"January\", \"March\", \"December\" , \"October\" ]

And I want to have it sorted like this:

[\"         


        
10条回答
  •  被撕碎了的回忆
    2021-01-18 04:23

    For something like months, I'd just hard-code the arrays I needed...

    var correctOrdering = {
        english: ["January", "February", "March", ...],
        french: ["Janvier", "Février", "Mars", ...],
        russian: ["Январь", "февраль", "март"],
        ...
    };
    

    It's not like month names are going to change any time soon.

提交回复
热议问题