Brain Teaser: Recursive Anonymous Function Expression Analysis - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Brain Teaser: Recursive Anonymous Function Expression Analysis (1523 Views)
| Brain Teaser: Recursive Anonymous Function Expression Analysis by romme2u(op): 1:51am On Oct 20, 2018*. Modified: 12:53am On Oct 31, 2018 |
I have over-studied in recent weeks as I’ve read more than I write (code) ![]() There is a technique that has been flying over my head for over a year (probably because I didn’t take it serious at first). I came across it in Douglas Crockford’s “JavaScript the Good Parts” while studying advanced function techniques late last year. Here is a sample:
Here is it counterpart in PHP (Source – User Comment on PHP online manual):
Both piece of code uses same technique (Recursive Anonymous Function Expression) to solve two different problems. My issue is not recursive functions as I understand the concept. But since recursive function usually suffers from memory constraint and can most time be rewritten as iterative, I have never used it as iteration presents a more readable code to me. It seems the PHP code uses the Tower of Hanoi concept to rearrange the data structure. It is just a guess, I’m not really sure. Modified Thanks Nmeri17, the question didn't fit the Q&A format required by stack overflow.........I just needed to reword the question, sorry for the oversight. I have also provided context and expected data structure The correct question should be Convert these Recursive functions to Iterative functions (rewrite as) I understand that some problems suit recursive technique more than iterative but i just need an insight |
| Re: Brain Teaser: Recursive Anonymous Function Expression Analysis by romme2u(op): 1:56am On Oct 20, 2018 |
![]() |
| Re: Brain Teaser: Recursive Anonymous Function Expression Analysis by Nmeri17: 8:51am On Oct 22, 2018*. Modified: 9:24am On Oct 22, 2018 |
If you posted this on stack overflow, they're going to maim you with downvotes. You're seeking for help on an algorithm; didn't post your efforts on it so far, didn't mention the use case, didn't even as much as supply the arguments for your convoluted functions. Idk why I spent the last few hours on it. I literally reverse engineered the puzzle to come up with its arguments. Solving it was easier. I've added a couple comments so you can see what I'm doing
I'm afraid, the PHP solution will have to come some other time. I never reach to debug PHP code with phone ![]() BTW this is not a true anonymous function. It's recursing closures with higher order functions. If I show you a proper recursive anonymous function, you won't even be given variables like shell. The only thing you'll see is one entry point. How do you invoke a function tied to "nothing"? ![]() |
| Re: Brain Teaser: Recursive Anonymous Function Expression Analysis by talk2hb1(m): 9:33pm On Oct 22, 2018 |
romme2u: ?? |
| Re: Brain Teaser: Recursive Anonymous Function Expression Analysis by CodeHouse: 11:06pm On Oct 26, 2018*. Modified: 8:28am On Nov 22, 2018 |
romme2u:Firstly, don't over study again and don't crash your head. Secondly, bring your question to Nairaland, not that we don't have great minds here but codes are better interpreted with no smileys |
| Re: Brain Teaser: Recursive Anonymous Function Expression Analysis by Luminee(f): 11:20pm On Oct 26, 2018 |
CodeHouse: |
| Re: Brain Teaser: Recursive Anonymous Function Expression Analysis by AAinEqGuinea: 2:14am On Oct 27, 2018 |
Foreach keep it up Bro ![]() |
I Just Wrote My First JS Function ;D • Nairaland Login Function Is Faulty! • Javascript:how Do I Use drawBox Function.. • 2 • 3 • 4
Any Significant Difference In Internet Speed When Using Mifi Against Phone Hotsp • How To Become A Robotic Engineer Fast • Irish Teen Hacker Scares Microsoft Enough To Land Him A Job



??
keep it up Bro