alert( ( function( list ) {
return ( function( functor, nullValue, list ) {
if( list.length == 0 ) {
return nullValue;
}
var head = list.shift();
return functor( head, arguments.callee( functor, nullValue, list ) );
} )( function( head, tail ) {
return head * head + tail;
}, 0, list );
} )( [1, 2, 3, 4, 5] ) ); // will alert 55
用遞迴的方式算出一個陣列的平方和,使用 JavaScript。
靈感來自於 測測你自己 - The Joel on Software Translation Project。
對,我是故意寫成這樣的,這不算是好的風格...
靈感來自於 測測你自己 - The Joel on Software Translation Project。
對,我是故意寫成這樣的,這不算是好的風格...
沒有留言:
張貼留言