Question: I have this table :

[![enter image description here](https://i.stack.imgur.com/I1Jq7.png)](https://i.stack.imgur.com/I1Jq7.png)

I want to count the number of WKF\_NDI which have the same EQUIPMENT and max(DATE\_RECEIPT).

I try : 

```
select EQUIPMENT,DATE_RECEIPT,COUNT(WKF_NDI) from CMM_DB.REF_WKF_THEMIS_H323
where date_receipt in ( select max(date_receipt)from CMM_DB.REF_WKF_THEMIS_H323)
group by EQUIPMENT, DATE_RECEIPT;

```

Result : 

[![enter image description here](https://i.stack.imgur.com/TF2oi.png)](https://i.stack.imgur.com/TF2oi.png)

The output is just one line.

I want the output like this : 

```
PF2_SBAA-B  28/12/17 10:00:01,000000000 5
PF2_SBCC-D  27/12/17 16:50:01,000000000 5

```

Please Help.

Answer: 
You can use `Object.keys`, `Array.filter` and `Array.reduce` to achieve this:

```js
var objA = {key1:1, key2:2, key3:3};
var objB = {key1:4, key2:5, key3:6, key4:7, key5:8}
console.log(Object.keys(objB)
    .filter(key => objA[key])
    .reduce((obj, key) => {
        obj[key] = objB[key];
        return obj;
    }, {}));
```
Try a bit more modern JavaScript:

```js
function reduceObject(baseObject = {}, dataObject = {}) {
  return Object.keys(baseObject)
    .reduce((result, key) => {
      result[key] = dataObject[key];
      return result;
    }, {});
}
const objA = {key1:1, key2:2, key3:3};
const objB = {key1:4, key2:5, key3:6, key4:7, key5:8};

console.log(reduceObject(objA, objB));
console.log(reduceObject(objA));
console.log(reduceObject(undefined, objB));
console.log(reduceObject({ a: 'key' }, { a: 'thing', on: 'theFly' }));
```