softnshare / kata

Code Kata 這個概念是由 The Pragmatic Programmer 的作者之一Dave Thomas提出的, 想要提升自己的coding skill嗎? 歡迎加入這個slack channel, 加入請參考右邊網頁說明
https://softnshare.wordpress.com/slack/kata/
38 stars 4 forks source link

Once #10

Open jawayang opened 8 years ago

jawayang commented 8 years ago

題目:

You'll implement once, a function that takes another function as an argument, and returns a new version of that function that can only be called once.

Subsequent calls to the resulting function should have no effect (and should return undefined).

For example:

function foo() {
   console.log('foo');
}

fooOnce = once(foo)
fooOnce() // -> "foo"
fooOnce() // -> no effect

http://www.codewars.com/kata/5307ff5b588fe6d7000000a5/train/javascript

翻譯: 實現一個函數 once,它接受另一個函數作為參數,並返回該函數只能被調用一次的新版本。 所得到的函數的後續調用應該沒有任何效果(而且應該返回undefined) For example:

function foo() {
   console.log('foo');
}

fooOnce = once(foo) // 把foo傳入once得到新函數fooOnce 
fooOnce() // -> "foo"  (第一次調用fooOnce)
fooOnce() // -> no effect (第二次以後調用fooOnce 沒有任何效果)

by Larry Huang

vampireneo commented 8 years ago

PASS

jawayang commented 8 years ago

PASS

bucker commented 8 years ago

pass