Permalink
Browse files
refactor(limitTo): no need for all those checks if we use slice
- Loading branch information
Showing
with
4 additions
and
27 deletions.
-
+4
−27
src/ng/filter/limitTo.js
|
|
@@ -97,34 +97,11 @@ function limitToFilter() { |
|
|
limit = int(limit); |
|
|
} |
|
|
|
|
|
if (isString(input)) { |
|
|
//NaN check on limit |
|
|
if (limit) { |
|
|
return limit >= 0 ? input.slice(0, limit) : input.slice(limit, input.length); |
|
|
} else { |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
var i, n; |
|
|
|
|
|
// if abs(limit) exceeds maximum length, trim it |
|
|
if (limit > input.length) |
|
|
limit = input.length; |
|
|
else if (limit < -input.length) |
|
|
limit = -input.length; |
|
|
|
|
|
if (limit > 0) { |
|
|
i = 0; |
|
|
n = limit; |
|
|
//NaN check on limit |
|
|
if (limit) { |
|
|
return limit > 0 ? input.slice(0, limit) : input.slice(limit); |
|
|
} else { |
|
|
// zero and NaN check on limit - return empty array |
|
|
if (!limit) return []; |
|
|
|
|
|
i = input.length + limit; |
|
|
n = input.length; |
|
|
return isString(input) ? "" : []; |
|
|
} |
|
|
|
|
|
return input.slice(i, n); |
|
|
}; |
|
|
} |