Last active
December 21, 2015 04:09
-
-
Save ianpgall/6247244 to your computer and use it in GitHub Desktop.
JavaScript function to slice an Array-like object (same arguments as native Array.slice)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Slice = (function () { | |
"use strict"; | |
var func; | |
func = function (arr, start, howMany) { | |
var stop, newArr, i, j, cur; | |
start = +start || 0; | |
howMany = +howMany || Infinity; | |
stop = Math.min(start + howMany, arr.length); | |
newArr = []; | |
for (i = start, j = stop; i < j; i++) { | |
cur = arr[i]; | |
newArr.push(cur); | |
} | |
return newArr; | |
}; | |
return func; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment