Last active
August 29, 2015 14:06
-
-
Save huang-x-h/29ccc1af906ce7a7ab51 to your computer and use it in GitHub Desktop.
g()('al') = goal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//使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