Answer the question
In order to leave comments, you need to log in
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
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.
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 =)
There is an excellent course on coursera described by the following link . Also this author has a nice book for.
От себя могу только добавить, на днях нашел очень интересный ресурс - Rosettacode. Это некая википедия, там есть целый раздел о сортировке с примерами кода на различных языках.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question