mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
refactor(limitTo): no need for all those checks if we use slice
Closes #10537
This commit is contained in:
committed by
Peter Bacon Darwin
parent
eae848a712
commit
2caec44632
@@ -97,34 +97,11 @@ function limitToFilter() {
|
|||||||
limit = int(limit);
|
limit = int(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isString(input)) {
|
//NaN check on limit
|
||||||
//NaN check on limit
|
if (limit) {
|
||||||
if (limit) {
|
return limit > 0 ? input.slice(0, limit) : input.slice(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;
|
|
||||||
} else {
|
} else {
|
||||||
// zero and NaN check on limit - return empty array
|
return isString(input) ? "" : [];
|
||||||
if (!limit) return [];
|
|
||||||
|
|
||||||
i = input.length + limit;
|
|
||||||
n = input.length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return input.slice(i, n);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user