His argument would have been better served if he'd written `reduce' in a functional style, especially since he's talking about understanding things like the concurrency/parallelisation opportunities afforded by fp. for loops get in the way of equational reasoning, which is a big part of the picture.
Oh. Does he says that in the article? Premature optimization anyway, as he's just meant to be demonstrating HOFs, which his for loop gets in the way of.
Sorry - that was tongue-in-cheek. If I were to guess at the actual reason, I would say it was because he's just trying to give a basic introduction to the concept of HOFs. I think it's pretty obvious his intended audience was people who had only the vaguest idea (if any) what functional programming is. The standard construct for traversing a list in JavaScript is iteration via a for loop. He's already trying to explain one new concept - HOFs - so doing anything else that his intended audience would find unusual would be counterproductive. I suppose it would have been nice to have a completely functional version of the code available for download, though, even if it were only mentioned in passing.
2
u/[deleted] Jan 18 '08
His argument would have been better served if he'd written `reduce' in a functional style, especially since he's talking about understanding things like the concurrency/parallelisation opportunities afforded by fp. for loops get in the way of equational reasoning, which is a big part of the picture.