What are the requirements of the front-end of the big factory for the algorithm?

As a small front-end who has graduated for many years, the algorithm has long been returned to the teacher. ...

Compared with algorithms, I think data structures and design patterns are more important to the front end for three reasons:

1) The data types that JS can provide are really limited. Many times we use objects and arrays to solve problems simply and rudely, and write a bunch of complex business codes to support logic.

For example, if we want to do a carousel, we will naturally think of using arrays to record the list data of carousel pictures. We are more fashionable here, using the idea of vue data-driven view to realize it. We need to change the order of the pictures in the array every time the carousel turns pages. It looks ok. However, when the business is complex, such as we need to support loop playback and two-way playback, we need to make special judgments on the boundary values of the array, which reduces the maintainability of the code.

So if we think about it from another angle, we don't use arrays to define the picture list at first, but use linked lists? The problem is much simpler. However, the data structure of the linked list is not natively implemented by js, and we need to complete it ourselves.

Therefore, it is necessary to master the commonly used data structures and related methods.

2) Design pattern is an elegant solution to the problem under certain circumstances. I am bold and elegant here. Yes, a question often has more than one answer.

For example, I want to bind the click event to a series of buttons on the page and require the contents of the buttons to pop up when clicked. A simple and rude method is to add an onclick event to each button. Assuming that the number of buttons is very large or there are other click events to be executed on this button, this scheme is not so feasible. Some students thought of using event delegation, yes, here you use a design pattern, proxy pattern. It is clear at a glance which is better or worse.

I think every business scenario has a suitable and elegant solution, which is the design pattern.

3) Generally speaking, the amount of data to be processed by the front end and the computational complexity are not high. For example, if I want to find the maximum value in an array, generally I will use the sorting method of the array directly, without considering writing a bubble or a quick line myself. If you really want to process a large amount of data, it is debatable whether this processing process should be put on the front end.

The problem is that it needs to be abstracted constantly, and the degree of abstraction is directly proportional to experience and ability.