Created
December 19, 2011 18:23
-
-
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.
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
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