This function can take multiple arguments, either as a List or an Array.
listOrArray(1, 2, 3);// List
listOrArray(["a", "b", "c"]);// Array| function listOrArray(Arr) { | |
| var List = Array.prototype.slice.call(arguments, 1), | |
| i; | |
| // If `List` is not empty, assume there are more module objects sent as List Arguments | |
| if (List.length > 0) { | |
| List.unshift(Arr); | |
| Arr = List; | |
| } else { | |
| // No List args in sight, treat the first arg `Arr` as an array and loop through it. | |
| // Even if there's just one. | |
| Arr = [].concat(Arr); | |
| } | |
| // Loop through that array | |
| for (i in Arr) { | |
| if (Arr.hasOwnProperty(i)) { | |
| // Do something | |
| } | |
| } | |
| } |