Skip to content

Instantly share code, notes, and snippets.

@mbeloshitsky
Last active March 4, 2016 09:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbeloshitsky/399b97dd2d0fdd4b0950 to your computer and use it in GitHub Desktop.
Save mbeloshitsky/399b97dd2d0fdd4b0950 to your computer and use it in GitHub Desktop.
function func(x, n) {
if (n != 1) {
return x * func(x, n - 1);
} else {
return x;
}
}
alert(func(4, 3));
// 1
function func(x, n) {
if (n != 1) {
return x * func(x, n - 1);
} else {
return x;
}
}
alert(function func(4, 3) {
if (3 != 1) {
return 4 * func(4, 3 - 1);
} else {
return 4;
}
});
// 2
function func(x, n) {
if (n != 1) {
return x * func(x, n - 1);
} else {
return x;
}
}
alert(4 * func(4, 3 - 1)) = alert(4 * func(4, 2));
// 3
function func(x, n) {
if (n != 1) {
return x * func(x, n - 1);
} else {
return x;
}
}
alert(4 * function func(4, 2) {
if (2 != 1) {
return 4 * func(4, 2 - 1);
} else {
return 4;
}
});
// 4
function func(x, n) {
if (n != 1) {
return x * func(x, n - 1);
} else {
return x;
}
}
alert(4 * (4 * func(4, 2 - 1))) = alert(4 * 4 * func(4, 1));
// 5
function func(x, n) {
if (n != 1) {
return x * func(x, n - 1);
} else {
return x;
}
}
alert(4 * 4 * function func(4, 1) {
if (1 != 1) {
return 4 * func(4, 1 - 1);
} else {
return 4;
}
});
// 6
function func(x, n) {
if (n != 1) {
return x * func(x, n - 1);
} else {
return x;
}
}
alert(4 * 4 * 4) = alert(64);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment