Skip to content

Instantly share code, notes, and snippets.

@justinobney
Created December 19, 2011 18:23
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 justinobney/1498270 to your computer and use it in GitHub Desktop.
Save justinobney/1498270 to your computer and use it in GitHub Desktop.
Would like to add "makeArray" to QUnit. This will hopefully allow me to compare objects to arrays for equality.
function makeArray(array, results) {
var ret = results || [];
function merge(first, second) {
var i = first.length,
j = 0;
if (typeof second.length === "number") {
for (var l = second.length; j < l; j++) {
first[i++] = second[j];
}
} else {
while (second[j] !== undefined) {
first[i++] = second[j++];
}
}
first.length = i;
return first;
}
if (array != null) {
// The window, strings (and functions) also have 'length'
var type = QUnit.objectType(array);
if (array.length == null || type === "string" || type === "function" || type === "regexp") {
push.call(ret, array);
} else {
merge(ret, array);
}
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment