Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit cd77c08

Browse files
kwypchlolgalfaso
authored andcommitted
perf(limitTo): replace for loop with slice
1 parent 83f88c1 commit cd77c08

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/ng/filter/limitTo.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ function limitToFilter() {
106106
}
107107
}
108108

109-
var out = [],
110-
i, n;
109+
var i, n;
111110

112111
// if abs(limit) exceeds maximum length, trim it
113112
if (limit > input.length)
@@ -119,14 +118,13 @@ function limitToFilter() {
119118
i = 0;
120119
n = limit;
121120
} else {
121+
// zero and NaN check on limit - return empty array
122+
if (!limit) return [];
123+
122124
i = input.length + limit;
123125
n = input.length;
124126
}
125127

126-
for (; i < n; i++) {
127-
out.push(input[i]);
128-
}
129-
130-
return out;
128+
return input.slice(i, n);
131129
};
132130
}

0 commit comments

Comments
 (0)