+ 17
Array sorting. HELP😱
I have such array: ["1,5 x 1m", "2,5 x 2 m", "1x2,5m", "no", "1,4 x 2 m", "9 x 1,4m + 1,5 x 4m", "yes", "1,4 x 2,3 m" ] I need such output: [ "yes", "no", "1x2,5m", "1,4x2m", "1,4x2,3m", "1,5x1m", "2,5x2m", "9x1,4m+1,5x4m", ]; How to sort source array more effectively, concise and elegant? ONLY JAVASCRIPT SOLUTION!!! PS. I know it's simple, but can't guess how... Should I use sort(), filter(), map() and so on functions and tricky callback? Notice,commas in elements and different spaces in source array!
10 Answers
+ 15
it's interesting🤓
+ 15
Thanks, Aleksey👏
+ 14
Real programming consists entirely of such boring things😁 And usually you don't have time to enjoy and use new tecnologies. In a real market, you need to solve about such problems.😏
Of course you can create cool animations and interesting logic, but clients need from your code to work everywhere and steadily
+ 14
+ 12
And I knew it too😉. Give me the ready solution, @silent. I know theory rather well, but can't to solve many tasks yet, @silent
+ 11
yes, I knew it, but thanks to you, @silent
+ 8
I knew that you knew this, too.
And as for the ready solution, it is necessary to think, it is long and tedious... :(
+ 8
Nope. It's boring and needs to think about it.
+ 7
I started doing this with `Array.prototype.sort()`... and I was tired. I think we should split the values like "9x1,4m+1,5x4" into multiple parts, go through them with `parseFloat()` or `parseInt()` (I do not understand this), and compare by these values.
I think I said obvious things that will not help
+ 7
If commas can be replaced with points, then it is easier.