add compact.md & ran npm run build-list

This commit is contained in:
King
2017-12-14 01:19:15 -05:00
parent d3956684b8
commit 2a3654ccac
2 changed files with 18 additions and 1 deletions

8
snippets/compact.md Normal file
View File

@ -0,0 +1,8 @@
### Compact
Use `.filter()` to filter falsey values. For example false, null, 0, "", undefined, and NaN are falsey.
```js
const compact = (arr) => arr.filter( v => [0, null, false, '', undefined].indexOf(v) === -1 && v);
// compact([0, 1, false, 2, '', 3, 'a', 'e'*23, NaN, 's', 34]) -> [ 1, 2, 3, 'a', 's', 34 ]
```