Question: I'm trying to compare a list of dictionaries to list and if there is a match increment rank. Is there a better way(more efficient way) to do this. My code:

```
requirements = ["JSF","JSP","Spring"]
Employee_records = [{'job_seeker_id': 1, 'skills': ['Spring', 'JSP', 'JSF'], 'experience': '5 years', 'location': 'stockholm', 'rank': 3}, {'job_seeker_id': 2, 'skills': ['Servlets', 'JSP'], 'experience': '2 years', 'location': 'gothenburg', 'rank': 1}, {'job_seeker_id': 3, 'skills': ['JSP'], 'experience': '4 years', 'location': 'lund', 'rank': 1}, {'job_seeker_id': 4, 'skills': ['Servlets'], 'experience': '3 years', 'location': 'malmo', 'rank': 0}, {'job_seeker_id': 5, 'skills': ['Hibernate', 'Servlets'], 'experience': '1 years', 'location': 'stockholm', 'rank': 0}]

for dict_ in Employee_records:
    for elm in dict_["skills"]:
        for skill in requirements:
            if elm == skill:
                dict_["rank"]+=1

```

Answer: 
Use `_.flatMap()` to get a flattened array of `operations`, and then use `_.uniqBy()` to get only items with unique `name`:

```js
const data=[{ id: 'id-1', uniqueName: 'operation-level-1', operations: [ { name: 'operaion-1', label: 'operation-1-label' }, { name: 'operaion-2', label: 'operation-2-label' } ] }, { id: 'id-2', uniqueName: 'operation-level-2', operations: [ { name: 'operaion-1', label: 'operation-1-label' }, { name: 'operaion-3', label: 'operation-3-label' } ] }];

const result =  _.uniqBy(
  _.flatMap(data, 'operations'),
  'name'
);

console.log(result);
```

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js"></script>
```

With lodash/fp you can generate a function using `_.flow()` that flattens `operations`, and then get the unique values by `name`:

```js
const fn = _.flow(
  _.flatMap('operations'),
  _.uniqBy('name')
)

const data=[{ id: 'id-1', uniqueName: 'operation-level-1', operations: [ { name: 'operaion-1', label: 'operation-1-label' }, { name: 'operaion-2', label: 'operation-2-label' } ] }, { id: 'id-2', uniqueName: 'operation-level-2', operations: [ { name: 'operaion-1', label: 'operation-1-label' }, { name: 'operaion-3', label: 'operation-3-label' } ] }];

const result = fn(data);

console.log(result);
```

```html
<script src='https://cdn.jsdelivr.net/g/lodash@4(lodash.min.js+lodash.fp.min.js)'></script>
```
There is no need for loadash, a simple `Map` object, will allow you to suppress the duplicates.

```js
const arr = [{
    id: 'id-1',
    uniqueName: 'operation-level-1',
    operations: [{
        name: 'operaion-1',
        label: 'operation-1-label'
      },
      {
        name: 'operaion-2',
        label: 'operation-2-label'
      }
    ]
  },
  {
    id: 'id-2',
    uniqueName: 'operation-level-2',
    operations: [{
        name: 'operaion-1',
        label: 'operation-1-label'
      },
      {
        name: 'operaion-3',
        label: 'operation-3-label'
      }
    ]
  }
];

// Go thought the arr and add all the name/label into the map
// Then use Array.from to reformate the Map into the wanted format
const uniqueArr = Array.from(arr.reduce((tmp, {
  operations,
}) => {
  operations.forEach(({
    name,
    label,
  }) => {
    tmp.set(name, label);
  });

  return tmp;
}, new Map())).map(([name, label]) => ({
  name,
  label,
}));

console.log(uniqueArr);
```