Question: I am working on some code I am unfamiliar with.

I have a data set that looks like this:

```
[
 {"id": 1, "person_name": "joe", "parent_id": "1ax"}
 {"id": 2, "person_name": "jane", "parent_id": "5t6"}
 {"id": 3, "person_name": "john", "parent_id": "a88"}
]

```

Originally the code has this line:

```
const values = this.data.map((d) => d.person_name).sort();

```

and then this:

```
groups = Object.values(
            values.reduce((a, c) => {
                (a[c] || (a[c] = { name: c, rcount: 0 })).rcount += 1;
                return a;
            }, {})
        ).sort(({ rcount: ac }, { rcount: bc }) => bc - ac);

```

This all results in something like this:

```
[
 {name: "joe", rcount: 1},
 {name: "jane", rcount: 1},
 {name: "john", rcount: 1}
]

```

I'd like to include the parent\_id in the final output too but can't figure out how.

I've tried a number of things in the `.map()` section but none have yet worked.

I tried this for example:

```
const values = this.data.map((d) => d.person_name, d.parent_id).sort();

```

Is there a way I can map to an object and then reference the person\_name and the parent\_id from values when doing the reduce?

Answer: 
If you don't care to keep the first 100 bytes, simply create 100 lengths of string, change some values and write it to the stream would be enough. Reading a file is not needed.

```
std::fstream fs("text.txt", ios_base::out | ios_base::binary);

string buffer(100, ' ');
string update="Hello";
buffer.replace(0, update.size(), update);

fs.seekp(20);   // move to write position
fs.write(buffer.data(), buffer.size());

fs.close();

```
Use ios::trunc as the file open mode.
For more info check out [this](http://www.cplusplus.com/doc/tutorial/files/).