public
Created

booh!

  • Download Gist
to-args.js
JavaScript
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);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.