Use more for-of

This commit is contained in:
Michał Lipiński
2017-04-05 09:05:58 +02:00
parent 2538a56577
commit b506174410
3 changed files with 16 additions and 14 deletions

View File

@@ -12,13 +12,14 @@
* // => [1, 2, 3]
*/
function compact(array) {
let index = -1
let resIndex = 0
const length = array == null ? 0 : array.length
const result = []
while (++index < length) {
const value = array[index]
if (array == null) {
return result
}
for (const value of array) {
if (value) {
result[resIndex++] = value
}