Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Functional Programming needs some real world use cases Date: Thu, 19 Jan 2017 20:10:18 +0000 Organization: A noiseless patient Spider Lines: 21 Message-ID: <87bmv2erpx.fsf@bsb.me.uk> References: <8b2dc802-a0d2-4ae0-ba75-98ecf5989e64@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="2cdf34f8ad320d53510d792e611eaef0"; logging-data="28291"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EBKuEo6ttYbuxfB50P+veXvmN5LfGXRY=" Cancel-Lock: sha1:A3txNaFWYqgujYaT16tiozOa+Uk= sha1:9otCt3j5vzH4O6GbeOM0+mvCxv0= X-BSB-Auth: 1.ece75958d781bcac23d7.20170119201018GMT.87bmv2erpx.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:32198 justaguy writes: > I'm starting to read about Functional Programming. The following is > some sample code, which seems concise. In the meantime, I wonder if > you have some idea of using other "action" other than "print", and of > course, feel free to use other array "values" where appropriate. > > function forEach(array, action) { > for (var i = 0; i < array.length; i++) > action(array[i]); > } > > forEach(["Wampeter", "Foma", "Granfalloon"], print); As an exercise, what expression can you write in place of "..." to print all seven strings (and just those): forEach([["a","b","c"],["q","r"],["z"]], ...); -- Ben.