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: 
```
var objA = { key1: 1, key2: 2, key3: 3 };
var objB = { key1: 4, key2: 5, key3: 6, key4: 7, key5: 8 };

objB = Object.keys(objB).reduce(function(result, key) {
  if (objA.hasOwnProperty(key)) {
    result[key] = objB[key]
  }

  return result;
}, {});

```

This is a ES5 version which doesn't use the `delete` operator but instead constructs a new object which only has the keys from `objA` and assigns it to `objB`.
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' }));
```