The introduction

When it comes to data structures, a lot of people started to head, because the feeling like what data structure, algorithm concepts such as are very tall, I know there are a lot of classmates think programming high salary after graduation, or train crash so he chose a language, which was engaged in this industry, but for some basic programming language, Series as well as relevant knowledge structure is missing, so spare time to spend more time to learn more, actually can be fill up, take myself for example, I though is not “computer science and technology” is not “software engineering” pure computer professional, but is related to computer professional discipline, so to go to school, Contact with C, Java, C # language, there are some data structure, the concept of database operations knows a thing or two, or series of learned basic courses such as computer network, although the school learning is not good also not fine, but there is at least the ideas and concepts, so in this also gives some just into the technology, or turned a little hint of classmates, In addition to the technical language and busy business logic of the job, these basic concepts should be covered.

What is a data structure

A data structure is a way of storing and organizing data

As for what time I had about the concept of “data structure”, should be in July of this year, joined the company, contact complex business logic, processing complex data, the company has a special department team of dozens of big data, so it is conceivable that each processing interface return data, is no longer a single structure of data before, It’s relatively complex, reasonably designed interface data, so you get the data directly, it’s not directly usable, it requires you to do secondary processing before you can use the data for presentation or processing logic

Take a chestnut

Such as we get to the period of such data, but we need to come up to add a field in the data, such as the need to give each item a “country” the field, so we need the a set of data, and the array is the most simple memory data structure, and almost all language support in js array type, So learn js data structure, the first thing to learn is to deal with the array





Snippets of data

Javascript language has been constantly improved and updated, es6 last year, and es7 this year, the methods and API involved in the array are also constantly improved, this article will not introduce es5 method extension, if you need to check the relevant materials to learn, let’s first take a general overview of common can efficiently handle the array method. These methods can help us deal with a lot of simple logic in our daily work

Commonly used for processing data: a traversal method

ForEach (),map(), some()/every(), filter(),reduce()/reduceRight() all have a traversal function, but they also have their specific functions in traversal. The above methods are often used by me in processing array data. If you haven’t used them before or if you don’t use them fully, you can search for their respective functions

2. Array deduplication

Thinking about? How do I remove duplicate items from an array

For example, array: [1,3,4,3,5] when we do deduplication, at first we must think of comparing one by one, the outer layer of the loop, the inner layer of the last one with the previous one, if the current item is not put into a new array for a long time, after comparison, return a new array that has been repeated





Bad practice

The above method is extremely inefficient, the amount of code is also too much, think? Is there a better way

At this time can not help but take it for granted!! A hashtable is an efficient way to remove duplicate content by using the hash method of objects





Successfully output the deduplicated array

? Since the array methods are so complete, there are better ways to traverse





Use forEach instead of the for loop

At last! How do you duplicate a data structure in an array where each item is a complex object type instead of a simple data type?

For example, the array looks like this:





The first term and the last term repeat

We’re still using the hash idea, but to think differently, we can treat each item in this array as a property of an object, and then enumerate that property





Attach tips


Keys () returns an array of attributes, which we then iterate over and perform a callback for each item using the array’s map() method. Map () returns a new array

The end

Or more smaller chestnuts, starting with the most of our old thoughts and inefficient method step by step at the end of the array to repeat miscellaneous, this one process embodies the fun of the array, but also reflects the charm of the data structure, an array is a kind of simple data structure, there are many more complex and more conscious knowledge waiting for us to dig, I also hope that partners can share more knowledge and fun with me. In 2107, you are welcome to be an intellectual who keeps studying hard with me

Note: The pictures in the article are from my screenshots, the text is original, please indicate the source

Cayley is a woman programmer who keeps learning