D
D
Dmitry Esin2016-11-14 23:23:07
JavaScript
Dmitry Esin, 2016-11-14 23:23:07

How to learn to sort any complexity in JavaScript?

Actually, a bug with data sorting.
There is no special education, perhaps there is a gap here.
Often you have to deal with sorting an array of objects of various nesting (including immutable data structures like Map, List from Immutable.js).
How map(), sort(), reduce() work is generally understandable, but it is very difficult to apply them effectively live.
Is there any universal solution for this topic?
Perhaps you should read some textbook on algorithms and data structures or take a course with tasks on the application of these methods.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
X
xmoonlight, 2016-11-15
@xmoonlight

1. here
2. methods and complexity of sorting

D
Denis Kiselev, 2016-11-22
@deksden

Little advice. Instead of sorting a large data structure (like an array of objects), you can make and sort an auxiliary index array. In the initial state, the array consists of elements 0,1,2,3,... - according to the number of elements of the original array. During sorting, it is not the original array that is sorted, but the auxiliary one - but the comparison operators use the original array.
What is the profit? Less memory is shuffled by adding or removing array elements.

S
Sergey Nekrasov, 2016-11-16
@Judixel

Learn

Z
ZloyHobbit, 2016-11-24
@ZloyHobbit

If you are interested in sorting, then the language is not important, you need to study algorithms.
www.ozon.ru/context/detail/id/6290126 is one of the best books to start with in my opinion. Much smaller and simpler than Knut, or Kormen. Well, there are enough tips with books on algorithms on the Toaster.
Well also it is necessary to distinguish sortings and bypasses. Methods like map and reduce call some function for each element of the array. They just walk over it, without comparison.
sort - sorts an array, that is, compares the elements with each other and rearranges them. The complexity of such an algorithm is usually much higher than with a simple pass, and the comparison can be done in various ways, and this can be controlled by passing the comparison function arr.sort(function). But this function will only change the principle of comparing two array elements, and not the sorting algorithm, which is responsible for the order of comparison and permutation. By passing a custom function, we can, for example, sort numbers alphabetically, or in reverse order, using the same sorting algorithm.
Well, if you need to implement your own algorithm, then you need to write your own sorting method =)

C
click_f, 2016-11-16
@click_f

There is an excellent course on coursera described by the following link . Also this author has a nice book for.

Богдан Герасименко, 2016-11-24
@Kleindberg

От себя могу только добавить, на днях нашел очень интересный ресурс - Rosettacode. Это некая википедия, там есть целый раздел о сортировке с примерами кода на различных языках.

Андрей, 2016-11-29
@iCoderXXI

Попробуй посмотреть в сторону Lodash/Underscore, там есть масса оптимизированных методов для, в т.ч., и сортировок по нескольким полям в разных направлениях.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question