Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does y(x) do in this arrow funtion

I do not get what y(x) in the third line does

var x = 5;

var y = 1;

( (x, y)=>(y => y(x) + 1)(x => x * 3 + y) ) (x, y);

// returns 17 

I suspect that the f(x) calls the arrow function on the right.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

That:

(y => y(x) + 1)

is a lambda (an anonymous function) that takes a function y as an argument.

Its argument is:

(x => x * 3 + y)

Thus it is the same as:

((x => x * 3 + y)(x) + 1)
((x*3)+y)+1

and all this is part of a function ((x, y)=> …) which is applied with the arguments (5,1).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading