Brainfade time - what's the proper name for a 'local' handler?

Robert Mann rman at free.fr
Thu May 27 14:10:33 CDT 2010


>   // Return a list of all books with at least 'threshold' copies sold. 
>   function bestSellingBooks(threshold) { 
>     return bookList.filter( 
>         function (book) { return book.sales >= threshold; } 
>       ); 
>   } 

did I get it right?? as I understand it, the "closure" replaces a loop?
Assuming the function book loops through the books?

for the example I assume we have a pile of cards for each book...

function bestSellingBooks threshold
put the number of cards of stack books into numberOfBooks
put empty into theResult

for i = 1 to numberOfBooks
put field theSales of card i into @iSales
 put booklistFilter (threshold, @sales) after theResult
end loop

return theResult
end function

function bookListFilter threshold, sales

     if sales > threshold then return sales &"," else return empty

end function

if that is right, yeak closure is more compact & elegant!
but did I miss something? brainfade!




-- 
View this message in context: http://runtime-revolution.278305.n4.nabble.com/Brainfade-time-what-s-the-proper-name-for-a-local-handler-tp2233056p2233641.html
Sent from the Revolution - User mailing list archive at Nabble.com.



More information about the use-livecode mailing list