Skip to content

Instantly share code, notes, and snippets.

@warpdesign
Last active December 25, 2015 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warpdesign/6936824 to your computer and use it in GitHub Desktop.
Save warpdesign/6936824 to your computer and use it in GitHub Desktop.
Test
function isArray(arr) {
return Object.prototype.toString.call(arr) === '[object Array]';
}
function foreach(arr, handler) {
if (isArray(arr)) {
for (var i = 0; i < arr.length; i++) {
handler(arr[i]);
}
}
else
handler(arr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment