javascript - ES6 Arrow Notation with Loops -


consider following bit of code:

f=(m,c)=>{m?c()&f(--m,c):0} 

(thanks zzzzbov little nugget)

which "for"-less loop

and following:

a=b=>b+1 

given these 2 snippets, , fact that:

z = 0; f(10,a(z)); 

which expect result in z equating 10, instead returns in javascript console following "typeerror: c not function", how 1 go altering code ensure loop goes ahead, without having resort while or for loop?

i'm asking matter of education purposes... can insight can done...

the function f taking 2 arguments: m, number iterate, , c, function called m times. means second argument, c should function. example:

f=(m,c)=>{m?c()&f(--m,c):0}   f(15, function() {  console.log("hello") }) 

this iterate through c function 15 times, calling console.log 15 times.

of course, achieve wanted in second bit, use this:

z=0, f(10,()=>z++) 

this regular arrow function increase z 1

take @ code on babel

hope help!


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -