Skip to content

@gjohnson /to-args.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
booh!
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
Something went wrong with that request. Please try again.