Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

booh!

View to-args.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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.