Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
40
rated 0 times [  41] [ 1]  / answers: 1 / hits: 18381  / 8 Years ago, mon, may 2, 2016, 12:00:00

We dont use for loop in functional programming, instead, we use higher order functions like map, filter, reduce etc. These are fine for iterating through an array.



However, I wonder how do I do a simple counter loop.



let i = 0;
for( i; i < 10; i++) {
console.log( functional programming is a religion)
};


So, how would one do this in functional programming?


More From » loops

 Answers
29

Do not use 'while' or 'for' that is to control flows of Imperative Programming not Functional.



Array(10).fill(functional programming is not a religion)
.map((msg) => {
console.log(msg);
return msg;
});

[#62335] Thursday, April 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daja

Total Points: 407
Total Questions: 103
Total Answers: 103

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
daja questions
Tue, Dec 21, 21, 00:00, 2 Years ago
Thu, Apr 23, 20, 00:00, 4 Years ago
Fri, Sep 6, 19, 00:00, 5 Years ago
Tue, Jul 23, 19, 00:00, 5 Years ago
;