Created
December 29, 2012 22:25
-
-
Save gjohnson/4409706 to your computer and use it in GitHub Desktop.
booh!
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 assert = require('assert') | |
, result; | |
function toArgs(val){ | |
if (Array.isArray(val[0])) return val[0]; | |
var len = val.length; | |
var ret = new Array(len); | |
for (var i = 0; i < len; ++i) { | |
ret[i] = val[i]; | |
} | |
return ret; | |
} | |
// varargs | |
result = (function(){ | |
return toArgs(arguments); | |
})('a', 'b', 'c'); | |
assert(result instanceof Array); | |
assert(result.length == 3); | |
// arrays | |
result = (function(){ | |
return toArgs(arguments); | |
})(['a', 'b', 'c']); | |
assert(result instanceof Array); | |
assert(result.length == 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment