1234567891011121314151617181920212223242526272829303132333435 |
- /**
- * Create slice of source array or array-like object
- */
- function slice(arr, start, end){
- var len = arr.length;
- if (start == null) {
- start = 0;
- } else if (start < 0) {
- start = Math.max(len + start, 0);
- } else {
- start = Math.min(start, len);
- }
- if (end == null) {
- end = len;
- } else if (end < 0) {
- end = Math.max(len + end, 0);
- } else {
- end = Math.min(end, len);
- }
- var result = [];
- while (start < end) {
- result.push(arr[start++]);
- }
- return result;
- }
- module.exports = slice;
|