Skip to content

Instantly share code, notes, and snippets.

@tarsisazevedo
Created May 18, 2011 17:41
Show Gist options
  • Save tarsisazevedo/979087 to your computer and use it in GitHub Desktop.
Save tarsisazevedo/979087 to your computer and use it in GitHub Desktop.
// create a function that accepts two arguments and return them reverted
function revert(a, b){
return [b, a];
}
// create a function that no accepts arguments and return them reverted
function revert(){
return [ arguments[1], arguments[0] ];
}
// create a function that reverse all arguments
function revert() {
var reversedArgs = [];
for(i = arguments.length -1 ; i >= 0; i--){
reversedArgs.push(arguments[i]);
}
return reversedArgs;
}
// create a function that return thar arguments incremented
function soma(a, b) {
a++;
b++;
console.log(a, b);
}
// create a function that accepts two args: { a: 1}, { b: 2 } and increment
function incrementObjects(a, b){
a.a++
b.b++
console.log(a, b);
}
// create a function same as 5 but not modify original objects
function incrementObject(a, b){
var x a.a;
var y = b.b;
console.log(x++, y++);
}
function fn(foo, a, b){
foo(a, b);
}
// 10
function fn(foo) {
var inner = function() {};
inner.foo = foo;
return inner;
}
var ret = fn(console.log);
ret.foo === console.log;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment