use `filter()` here.
```javascript
var detectFunc = (type === 0 ? 'isFile' : 'isDirectory');
return files.filter(function(file) {
  return file[detectFunc]();
}
```