Skip to content

Instantly share code, notes, and snippets.

@huang-x-h
Last active August 29, 2015 14:06
Show Gist options
  • Save huang-x-h/29ccc1af906ce7a7ab51 to your computer and use it in GitHub Desktop.
Save huang-x-h/29ccc1af906ce7a7ab51 to your computer and use it in GitHub Desktop.
g()('al') = goal
//使g()(‘al’)返回字符串”goal”;
//g()()(‘al’)输出”gooal”;
//代码g()()()(‘al’)返回goooal;
// 各个语言版本参考链接 https://github.com/eatnumber1/goal
// 一开始自己想的一个版本
function g() {
var stack = ['g'];
if (arguments.length === 0) {
return recursive;
} else {
stack.push(arguments[0]);
return stack.join('');
}
function recursive() {
stack.push('o');
if (arguments.length === 0) {
return recursive;
} else {
stack.push(arguments[0]);
return stack.join('');
}
}
}
// 更精简的版本
function g(al) {
g.q = g.q || 'g';
return al ? (g.q + al) : (g.q += 'o', g);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment