Question: am writing a program in java on Linked List. I get an error when i use toString to return the IP address and PC of the code below.

```
package linked;

import java.net.InetAddress;

public class Work {
    private InetAddress IP;
    private String PC;

    public Work(InetAddress IP, String PC){
        this.IP=IP;
        this.PC=PC;
    } 
    public InetAddress getIP(){
        return IP;
    }
    public String getPC(){
        return PC;
    }
    @Override
    public String toString() {
        return IP + ' ' + PC;
    }
}

```

It comes up with an error in the `@Override` that says 

> 
> bad operand types for binary operator '+' first type: InetAddress  
> 
>  second type: char
> 
> 
>

Answer: 
You can use [moment.isAfter](https://momentjs.com/docs/#/query/is-after/) and [Array.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) to clean the old dates and the `null` values.

```js
const dates = [
  "2018-04-02T15:15",
  "2018-04-07T14:20",
  "2018-04-28T11:50",
  null,
  null,
  null,
  null,
  "2018-05-30T17:45",
  "2018-04-07T16:20"
]

const futureDates = dates.filter(date => moment(date).isAfter())

console.log(futureDates);
```

```html
<script src="https://momentjs.com/downloads/moment.js"></script>
```

> 
> How do I get the count of just future dates?
> 
> 
> 

After using filter, only the valid dates remain, so:

```
console.log(futureDates.length);

```
Actually you don't even need to de nest them. If you want to filter an array you should use `Array.filter`. IT has the footprint of `(value, index, originalArray) => Boolean` with a true meaning keep, and a false meaning remove:

```
let currentTime = new Date();
let futureconsultas = resp.consultas.filter( consultas =>
  new Date(consultas.date_a) - currentTime > 0
);

```

Now you should have an array of all future dates  

 - As a note: `new Date() - new Date('INVALID')` returns `NaN` which evaluates to false when compared to a number or when masked, so you don't have to worry about bad dates. A `new Date(null)` argument results in epoch 0, which is NOT before now, and `new Date(undefined)` results in an bad date  

 - A second note: You shouldn't use a `new Date()` call in each loop. This can slow down execution if the array is large enough. Get a reference Date and use the Closure(scope) to reference it.

This works because when you math two `Date`s, they result is actually a number based on the epoch values of the date.

A simplified example:

```
const filtration = object => object.v > 3
console.log([{v:1},{v:2},{v:3},{v:4},{v:5}].filter(filtration)) // [{v:4},{v:5}]

```

After that you can just check the `.length` property on the Array

```
[1,2,3,4,5].length == 5 // true

```

Array has several helpful functions on the prototype in JS including forEach(mutating), filter, map, find, findIndex, and [more](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Javascript MDN page for Array")