Question: I'd like to sort an array without changing the index value. How can I achive this?

array:

```
let data = [];
data[12] = {"apples":1, "pears":2, "oranges":3};
data[25] = {"apples":3, "pears":3, "oranges":5};
data[18] = {"apples":4, "pears":1, "oranges":6};

```

I tried this:

```
function reorder(b, a) {
  return a - b;
}

```

but the output of reorder function is

```
data[0] = {"apples":3, "pears":3, "oranges":5};
data[1] = {"apples":4, "pears":1, "oranges":6};
data[2] = {"apples":1, "pears":2, "oranges":3};

```

and I'd like to achive something like this

```
data[25] = {"apples":3, "pears":3, "oranges":5};
data[18] = {"apples":4, "pears":1, "oranges":6};
data[12] = {"apples":1, "pears":2, "oranges":3};

```

Answer: 
Read the lines of both files into a separate variables. Iterate over the lines of the first file, and for each of one them check if they exist on the second file, if not then save them into the first file.

```
with open(file1, "r") as file1:
     lines_file1 = file1.readlines()
with open(file, "r") as file2:
     lines_file2 = file2.readlines()
     with open(file1, "w") as f_w:
           for line in lines_file1:
               if line not in lines_file2
                  f_w.write(line)

```

The downside of this approach is that you are loading the entire files into memory.
You can use **set operations** to do this with few lines of code.

Read two file and convert the list of lines into the set and use set operations

```
line_file1 = set(line_file1)
line_file2 = set(line_file2)
result = line_file1 - line_file2

```

Now write the **result** set each element (line) to the file.

**Note**: repeated data in file1 will be also removed.